Esempio n. 1
0
        /// <summary>
        /// 写入登录信息
        /// </summary>
        /// <param name="user">成员信息</param>
        public virtual void AddCurrent(OperatorEntity user)
        {
            try
            {
                if (_loginProvider == "Cookie")
                {
                    CookieHelper.WriteCookie(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()), 60);
                }
                else if (_loginProvider == "Session")
                {
                    SessionHelper.AddSession(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()), 60, 0);
                }
                else if (_loginProvider == "Cache")
                {
                    CacheFactory.GetCacheInstance().WriteCache(DESEncryptHelper.Encrypt(user.TryToJson()), LoginUserKey, user.LoginTime.AddMinutes(60));
                }

                //添加当前登陆用户Token
                CacheFactory.GetCacheInstance().WriteCache(user.Token, user.UserId, user.LoginTime.AddMinutes(60));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);//已登录
            }
        }