Пример #1
0
        /// <summary>
        /// 当前用户
        /// </summary>
        /// <returns></returns>
        public virtual OperatorEntity Current()
        {
            try
            {
                OperatorEntity user = new OperatorEntity();
                if (_loginProvider == "Cookie")
                {
                    user = DESEncryptHelper.Decrypt(CookieHelper.GetCookie(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();

                    #region 解决cookie时,设置数据权限较多时无法登陆的bug
                    AuthorizeDataModel dataAuthorize = CacheFactory.CacheFactory.GetCacheInstance().GetCache <AuthorizeDataModel>(LoginUserKey);
                    user.DataAuthorize = dataAuthorize;
                    #endregion
                }
                else
                {
                    user = DESEncryptHelper.Decrypt(SessionHelper.GetSession <string>(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();
                }
                return(user);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 是否已登录
        /// </summary>
        /// <returns></returns>
        public virtual int IsOnLine()
        {
            OperatorEntity user = new OperatorEntity();

            if (_loginProvider == "Cookie")
            {
                user = DESEncryptHelper.Decrypt(CookieHelper.GetCookie(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();

                #region 解决cookie时,设置数据权限较多时无法登陆的bug
                AuthorizeDataModel dataAuthorize = CacheFactory.CacheFactory.GetCacheInstance().GetCache <AuthorizeDataModel>(LoginUserKey);
                user.DataAuthorize = dataAuthorize;
                #endregion
            }
            else
            {
                user = DESEncryptHelper.Decrypt(SessionHelper.GetSession <string>(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();
            }
            object token = CacheFactory.CacheFactory.GetCacheInstance().GetCache <string>(user.UserId);
            if (token == null)
            {
                return(-1);//过期
            }
            if (user.Token == token.ToString())
            {
                return(1);//正常
            }
            else
            {
                return(0);//已登录
            }
        }
Пример #3
0
        private string namespaceName = "WIP_Test.TestService";//命名空间



        /// <summary>
        /// 加解密数据
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ReturnBody <string> GetEncryptData(GetEncryptData param)
        {
            ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <GetEncryptData>(namespaceName, "GetEncryptData", param);

            try
            {
                string result = "";
                if (param.isEncrypt == "0")
                {//加密
                    result = DESEncryptHelper.Encrypt(param.value);
                }
                else if (param.isEncrypt == "1")
                { //解密
                    result = DESEncryptHelper.Decrypt(param.value);
                }
                else
                {
                    return(BLLHelpler.GetReturnBody <string>(ResCode.FAILURE, ResMsg.FAILURE, "是否解密值错误"));
                }
                return(BLLHelpler.GetReturnBody <string>(ResCode.SUCCESS, ResMsg.SUCCESS, result));
            }
            catch (Exception ex)
            {
                WipLogHelper.GetExceptionInfoForError(ex, ref exception);
                return(BLLHelpler.GetReturnBody <string>(ResCode.FAILURE, ResMsg.FAILURE, exception, "出现错误:" + ex.Message));
            }
        }
Пример #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddLocalization(options => options.ResourcesPath = "Resources");
            services.AddMvc()
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
            services.Configure <RequestLocalizationOptions>(opts =>
            {
                var supportedCultures = new List <CultureInfo> {
                    new CultureInfo("en-US"),
                    new CultureInfo("zh-CN")
                };
                opts.SupportedCultures       = supportedCultures;
                opts.SupportedUICultures     = supportedCultures;
                opts.RequestCultureProviders = new List <IRequestCultureProvider> {
                    new X_DOVERequestCultureProvider()
                };
            });
            services.AddSession(options => options.IdleTimeout = TimeSpan.FromMinutes(30));

            services.AddResponseCompression();
            services.AddHangfire(config =>
            {
                config.UseStorage(new MySqlStorage("Server=39.104.53.29; uid = zaranet; pwd = 123456; database = amusinghoS;AllowUserVariables=True;    "));
            });
            //注入工作单元
            services.AddDbContext <amusinghoSDbContext>(options => options.UseMySql(DESEncryptHelper.Decrypt(
                                                                                        "wHMoKdCHCsMzxDTTN9+KOGSDC4JDdwxpukgfD+OGDS6W10AAz9lZac3QctGhAr+o1KGJbkuCLwdT4DXj/EM6eLnLKeVRATxDh21b0Jumpb8="
                                                                                        , "12345678")));
            services.AddTransient(typeof(UnitOfWork));
            services.AddScoped <IRedisClient, CustomerRedis>();
            var csredis = new CSRedis.CSRedisClient("39.104.53.29:6379,password=zaranet");

            RedisHelper.Initialization(csredis);

            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
            services.AddControllersWithViews();

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            services.AddAuthentication(options =>
            {
                options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            }).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => {
                options.ExpireTimeSpan = TimeSpan.FromSeconds(10);
            }).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options => {
                options.SignInScheme         = CookieAuthenticationDefaults.AuthenticationScheme;
                options.Authority            = "http://localhost:5000";
                options.RequireHttpsMetadata = false;
                options.ClientId             = "mvc client";
                options.ClientSecret         = "mvc secret";
                options.SaveTokens           = true;
                options.ResponseType         = "code";
                options.Scope.Clear();
                options.Scope.Add(OidcConstants.StandardScopes.OpenId);
                options.Scope.Add(OidcConstants.StandardScopes.Profile);
            });
        }
Пример #5
0
        /// <summary>
        /// 得到web.config里配置项的数据库连接字符串。
        /// </summary>
        /// <param name="configName"></param>
        /// <returns></returns>
        public static string GetConnectionString(string configName)
        {
            string connectionString = ConfigurationManager.AppSettings[configName];
            string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];

            if (ConStringEncrypt == "true")
            {
                connectionString = DESEncryptHelper.Decrypt(connectionString);
            }
            return(connectionString);
        }
Пример #6
0
        protected override void OnConfiguring(DbContextOptionsBuilder dbContextOptionsBuilder)
        {
            base.OnConfiguring(dbContextOptionsBuilder);

            if (!dbContextOptionsBuilder.IsConfigured)
            {
                string connection = DESEncryptHelper.Decrypt(
                    "wHMoKdCHCsMzxDTTN9+KOGSDC4JDdwxpukgfD+OGDS6W10AAz9lZac3QctGhAr+o1KGJbkuCLwdT4DXj/EM6eLnLKeVRATxDh21b0Jumpb8="
                    , "12345678");
                dbContextOptionsBuilder.UseMySql(
                    connectionString: connection);
            }
        }
Пример #7
0
 private void btnDencrypt_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtEncryptStr.Text))
     {
         try
         {
             MessageBox.Show(DESEncryptHelper.Decrypt(txtEncryptStr.Text));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Пример #8
0
        public void EncryptOrDecrypt()
        {
            //arrange
            string serverCoonection = "Server=39.104.53.29; uid = zaranet; pwd = 123456; database = amusinghoS;";
            var    miwen            = DESEncryptHelper.Encrypt(serverCoonection, "12345678");

            string connection = DESEncryptHelper.Decrypt(
                miwen
                , "12345678");
            //Act
            var result = DESEncryptHelper.Decrypt("BX+aN6+yUyRBOnwI/LJqs9ASfV9PCSaVeizUy8YKbumoFfQNzLZIhkEMDL5YSrETlyUXAlnJIfFuHGaexoXXUw+71cjSW630", "12345678");

            //Assert
            Assert.Equal(serverCoonection, result);
        }
Пример #9
0
 private void FrmLogin_Shown(object sender, EventArgs e)
 {
     chkMima.Checked = CYQ.Data.AppConfig.GetApp("IsSavePassword").ToString().Equals("true");
     if (chkMima.Checked)
     {
         string strAccount = CYQ.Data.AppConfig.GetApp("LoginAccount");
         if (!string.IsNullOrEmpty(strAccount))
         {
             this.tbUser.Text = DESEncryptHelper.Decrypt(strAccount);
         }
         string strPsd = CYQ.Data.AppConfig.GetApp("LoginPassword");
         if (!string.IsNullOrEmpty(strPsd))
         {
             this.tbPsd.Text = DESEncryptHelper.Decrypt(strPsd);
         }
     }
 }
Пример #10
0
        /// <summary>
        /// 解析请求头中的Token
        /// </summary>
        /// <returns></returns>
        protected string GetToken()
        {
            var req   = _accessor.HttpContext.Request;
            var token = req.Headers["token"];

            if (string.IsNullOrEmpty(token))
            {
                _accessor.HttpContext.Response.StatusCode = 401;
                throw new Exception("没有找到token");
            }
            string key = DESEncryptHelper.Decrypt(token, DateTime.Now.ToString("yyyyMMdd"));

            if (string.IsNullOrEmpty(key))
            {
                _accessor.HttpContext.Response.StatusCode = 401;
                throw new Exception("无效的token");
            }
            return(key);
        }
Пример #11
0
 /// <summary>
 /// 当前用户
 /// </summary>
 /// <returns></returns>
 public virtual OperatorEntity Current()
 {
     try
     {
         OperatorEntity user = new OperatorEntity();
         if (_loginProvider == "Cookie")
         {
             string json = CookieHelper.GetCookie(LoginUserKey).ToString();
             if (!string.IsNullOrEmpty(json))
             {
                 user = DESEncryptHelper.Decrypt(json).JsonToEntity <OperatorEntity>();
             }
         }
         else if (_loginProvider == "Session")
         {
             string json = SessionHelper.GetSession <string>(LoginUserKey).ToString();
             if (!string.IsNullOrEmpty(json))
             {
                 user = DESEncryptHelper.Decrypt(json).JsonToEntity <OperatorEntity>();
             }
         }
         else if (_loginProvider == "Cache")
         {
             string json = CacheFactory.GetCacheInstance().GetCache <string>(LoginUserKey);
             if (!string.IsNullOrEmpty(json))
             {
                 user = DESEncryptHelper.Decrypt(json).JsonToEntity <OperatorEntity>();
             }
         }
         return(user);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #12
0
        /// <summary>
        /// 是否已登录
        /// </summary>
        /// <returns></returns>
        public virtual int IsOnLine()
        {
            OperatorEntity user = new OperatorEntity();

            if (_loginProvider == "Cookie")
            {
                user = DESEncryptHelper.Decrypt(CookieHelper.GetCookie(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();
            }
            else if (_loginProvider == "Session")
            {
                user = DESEncryptHelper.Decrypt(SessionHelper.GetSession <string>(LoginUserKey).ToString()).JsonToEntity <OperatorEntity>();
            }
            else if (_loginProvider == "Cache")
            {
                string json = CacheFactory.GetCacheInstance().GetCache <string>(LoginUserKey);
                if (!string.IsNullOrEmpty(json))
                {
                    user = DESEncryptHelper.Decrypt(json).JsonToEntity <OperatorEntity>();
                }
            }

            string token = CacheFactory.GetCacheInstance().GetCache <string>(user.UserId);

            if (string.IsNullOrEmpty(token))
            {
                return(-1);//过期
            }
            if (user.Token == token.ToString())
            {
                return(1);//正常
            }
            else
            {
                return(0);//已登录
            }
        }
Пример #13
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var loginProvider = RequestHelper.GetSystemConfigByKey("LoginProvider");

            if (loginProvider == "Cookie")
            {
                var jsonuser = CookieHelper.GetCookieValue(SysConstant.SEESIONUSERKEY);
                if (!string.IsNullOrEmpty(jsonuser))
                {
                    UserInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <SysUserModel>(DESEncryptHelper.Decrypt(jsonuser));
                }
            }
            else
            {
                UserInfo = (SysUserModel)Session[SysConstant.SEESIONUSERKEY];
            }
            //if (UserInfo == null && !filterContext.ActionDescriptor.ActionName.Contains("Login"))
            //{
            //   // filterContext.Result = new RedirectResult("/Login");
            //    return;
            //}
            if (UserInfo == null)
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.HttpContext.Response.StatusCode = 401;//这个可以指定为其他的

                    //filterContext.Result = new JsonResult
                    //{
                    //    Data = "您长时间没有操作,请重新登录!",
                    //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    //};
                    filterContext.HttpContext.Response.End();
                }
                else
                {
                    //重置漏油
                    filterContext.Result = RedirectToRoute("Default", new { Controller = "Error", Action = "TimeOut" });
                }
            }
            else
            {
                ViewBag.UserName  = UserInfo.UserName;
                ViewBag.UserPhoto = UserInfo.UserPhoto;

                if (CacheHelper.Get <List <SysMenuModel> >("CurentMenu_" + UserInfo.UserCode) != null)
                {
                    CurentMenu      = CacheHelper.Get <List <SysMenuModel> >("CurentMenu_" + UserInfo.UserCode);
                    CurentMenuPower = CacheHelper.Get <Dictionary <string, List <string> > >("CurentPower_" + UserInfo.UserCode);
                }
                else
                {
                    GetUserMenu(UserInfo.UserCode);
                }
                base.OnActionExecuting(filterContext);
            }
        }
Пример #14
0
 public DatabaseManager()
 {
     Constr = DESEncryptHelper.Decrypt(ConfigurationManager.ConnectionStrings["SOACon"].ToString());
 }