Exemplo n.º 1
0
        /// <summary>
        /// 获取当前登录用户缓存信息的Key
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentUserCacheId()
        {
            List <string> list = DESUtils.Decrypt(CookieHelper.Get(KeyManager.IsMember)).ToList <string>();

            if (list != null && list.Count() == 2)
            {
                return(list[0]);
            }
            return("");
        }
Exemplo n.º 2
0
        public ActionResult ModifyUserPwd(ChangePasswordViewModel viewModel)
        {
            int userId = UserManager.GetCurrentUserInfo().Id;
            var result = WriteError("出现异常,密码修改失败");

            if (!SysUserService.CheckLogin(viewModel.UserName, viewModel.OldPassword))
            {
                return(WriteError("旧密码不正常"));
            }
            else
            {
                if (SysUserService.ModifyUserPwd(userId, viewModel))
                {
                    result = WriteSuccess("密码修改成功");
                    List <string> list = DESUtils.Decrypt(CookieHelper.Get(KeyManager.IsMember)).ToList <string>();
                    if (list == null || list.Count() != 2)
                    {
                        //获取缓存的用户信息
                        SysUser userinfo = CacheManager.Get <SysUser>(list[0]);
                        //删除缓存的用户信息
                        CacheManager.Remove(list[0]);
                        //更新缓存用户信息的KEY
                        list[0] = Guid.NewGuid().ToString();
                        if (list[1] == "0")
                        {
                            CacheManager.Set(list[0], userinfo, new TimeSpan(10, 0, 0, 0));
                            CookieHelper.Set(KeyManager.IsMember, DESUtils.Encrypt(list.ToJson()));
                        }
                        else if (list[1] == "1")
                        {
                            CacheManager.Set(list[0], userinfo, new TimeSpan(0, 30, 0));
                            CookieHelper.Set(KeyManager.IsMember, DESUtils.Encrypt(list.ToJson()), 30);
                        }
                    }
                }
                else
                {
                    result = WriteError("密码修改失败");
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 public string Get(string key, string defValue)
 {
     try
     {
         string spValue = sp.GetString(GetDigestKey(key), "");
         string value   = DESUtils.Decrypt(spValue, GetSecretKey());
         if (TextUtils.IsEmpty(value))
         {
             return(defValue);
         }
         else
         {
             return(value);
         }
     }
     catch (Exception e)
     {
         return(defValue);
     }
 }
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            //判断是否有贴跳过登录检查的特性标签(控制器)
            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }

            //方法
            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }

            if (!string.IsNullOrEmpty(CookieHelper.Get(KeyManager.IsMember)))
            {
                List <string> list = DESUtils.Decrypt(CookieHelper.Get(KeyManager.IsMember)).ToList <string>();
                if (list == null || list.Count() != 2)
                {
                    ToLogin(filterContext);
                    return;
                }
                SysUser userinfo = CacheManager.Get <SysUser>(list[0]);
                if (userinfo != null)
                {
                    // 0为永久key
                    if (list[1] == "0")
                    {
                        CacheManager.Set(list[0], userinfo, new TimeSpan(10, 0, 0, 0));
                    }
                    // 1为滑动key
                    else if (list[1] == "1")
                    {
                        CacheManager.Set(list[0], userinfo, new TimeSpan(0, 30, 0));
                        CookieHelper.Set(KeyManager.IsMember, DESUtils.Encrypt(list.ToJson()), 30);
                    }
                    else
                    {
                        ToLogin(filterContext);
                        return;
                    }
                }
                else
                {
                    ToLogin(filterContext);
                    return;
                }
            }
            else
            {
                ToLogin(filterContext);
                return;
            }

            //获得当前要执行的Action上标注的CheckPermissionAttribute实例对象
            CheckPermission[] permAtts = (CheckPermission[])filterContext.ActionDescriptor
                                         .GetCustomAttributes(typeof(CheckPermission), false);
            if (permAtts.Length <= 0)
            {
                return;
            }

            var container = CacheManager.Get <IContainer>(KeyManager.AutofacContainer);
            ISysActionService sysActionService = container.Resolve <ISysActionService>();

            //检查是否有权限
            foreach (var permAtt in permAtts)
            {
                //判断当前登录用户是否具有permAtt.Permission权限
                if (!sysActionService.HasPermission(UserManager.GetCurrentUserInfo().Id, permAtt.Permission))
                {
                    NoPermission(filterContext);
                    return;
                }
            }
        }