예제 #1
0
        public void FromAuthenticationTicket(HttpCookie cookie)
        {
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(cookie.Value);

            if (authTicket == null)
            {
                return;
            }
            var userData    = authTicket.UserData;
            var userDataArr = userData.Split('|');

            if (userDataArr.Length != 3 ||
                UserRep.GetIP() != userDataArr[1])
            {
                FormsAuthentication.SignOut();
                return;
            }
            if (FormsAuthentication.SlidingExpiration)
            {
                var expiration = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes);
                cookie.Expires  = expiration;
                cookie.HttpOnly = true;
                HttpContext.Current.Response.Cookies.Set(cookie);
            }
            var           userGid        = userDataArr[0];
            var           userGroup      = (UserGroup)Enum.Parse(typeof(UserGroup), userDataArr[2]);
            ISysUserModel serializeModel = UserRep.GetByCache(userGid);

            if (serializeModel == null)
            {
                var user = UserRep.GetByGid(userGid);
                if (user == null)
                {
                    UserRep.RemoveUserCache(userGid);
                    FormsAuthentication.SignOut();
                    return;
                }
                serializeModel = GetModel(user);
                UserRep.AddUserCache(serializeModel);
            }

            setPrinciple(serializeModel, userGroup);
        }
예제 #2
0
        private void setPrinciple(ISysUserModel model, UserGroup userGroup)
        {
            ISysUser sysUser = null;

            switch (userGroup)
            {
            case UserGroup.Admin:
                sysUser = new AdminUser((AdminUserModel)model);
                break;

            case UserGroup.Member:
                sysUser = new MemberUser((MemberUserModel)model);
                break;

            default:
                break;
            }
            if (sysUser != null)
            {
                HttpContext.Current.User = sysUser;
                Thread.CurrentPrincipal  = sysUser;
            }
        }
예제 #3
0
 public void AddUserCache(ISysUserModel model)
 {
     Cache.Add(GetUserCacheKey(model.GId), model, CacheTime);
 }
예제 #4
0
        private ISysUserModel GetModelFromCache(string userGid, UserGroup userGroup)
        {
            ISysUserModel serializeModel = UserRep.GetByCache(userGid);

            return(serializeModel);
        }