Ejemplo n.º 1
0
 /// <summary>
 /// 当前用户
 /// </summary>
 /// <returns></returns>
 public virtual Operator Current()
 {
     try
     {
         Operator user   = new Operator();
         string   userId = GetUserId();
         userId = "UID_" + userId + "_" + LoginUserKey;
         user   = CacheFactory.Cache().GetCache <Operator>(userId);
         if (user != null)
         {
             return(user);
         }
         if (LoginProvider == "AppClient")
         {
             if (string.IsNullOrEmpty(userId))
             {
                 user = CacheFactory.Cache().GetCache <Operator>("UID_" + AppUserId + "_" + LoginUserKey);
             }
             else
             {
                 user = CacheFactory.Cache().GetCache <Operator>(userId);
             }
         }
         else
         {
             string key = FormsAuth.GetUserKey();
             user = string.IsNullOrEmpty(key) ? null : CacheFactory.Cache().GetCache <Operator>("UID_" + key + "_" + LoginUserKey);
             if (user == null)
             {
                 if (string.IsNullOrEmpty(userId))
                 {
                     if (!string.IsNullOrEmpty(AppUserId))
                     {
                         user = CacheFactory.Cache().GetCache <Operator>("UID_" + AppUserId + "_" + LoginUserKey);
                     }
                 }
                 else
                 {
                     user = CacheFactory.Cache().GetCache <Operator>(userId);
                 }
             }
         }
         return(user);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 是否已登录
        /// </summary>
        /// <returns></returns>
        public virtual int IsOnLine()
        {
            Operator user = new Operator();
            string   key  = FormsAuth.GetUserKey();

            if (string.IsNullOrEmpty(key))
            {
                return(-1);
            }
            key  = "UID_" + key + "_" + LoginUserKey;
            user = CacheFactory.Cache().GetCache <Operator>(key);
            if (user == null)
            {
                return(-1);
            }
            //if (LoginProvider == "Cookie")
            //{
            //    //user = DESEncrypt.Decrypt(WebHelper.GetCookie(LoginUserKey).ToString()).ToObject<Operator>();
            //     //AuthorizeDataModel dataAuthorize = CacheFactory.Cache().GetCache<AuthorizeDataModel>(user.UserId + "_" + LoginUserKey);
            //}
            //else
            //{
            //    user = DESEncrypt.Decrypt(WebHelper.GetSession(LoginUserKey).ToString()).ToObject<Operator>();
            //}

            object token = CacheFactory.Cache().GetCache <string>(user.UserId + "_" + LoginUserKey);

            if (token == null)
            {
                return(-1);//过期
            }
            if (user.Token == token.ToString())
            {
                return(1);//正常
            }
            else
            {
                return(0);//已登录
            }
        }