Example #1
0
        /// <summary>
        /// 是否有效登录
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static AuthResult ValidateToken(string token)
        {
            Guid guid= ConvertHelper.GetGuid(token, Guid.NewGuid());

            AuthResult result = new AuthResult() { ErrorMsg = "Token不存在" };
            TokenInfo existToken = TokenManager.GetToken(guid);

            if (existToken != null)
            {
                #region 客户端IP不一致
                //if (existToken.RemoteIp != entity.RemoteIp)
                //{
                //    result.ErrorMsg = "客户端IP不一致";
                //}
                #endregion

                if (existToken.IsValid == false)
                {
                    result.ErrorMsg = "Token已过期" + existToken.ActivityTime.ToLongTimeString() + ":" + DateTime.Now.ToLocalTime();
                    TokenManager.RemoveToken(existToken.tokenId);//移除
                }
                else  
                {
                    result.User = new UserInfo() { UserId = existToken.UserId,UserName=existToken.UserName, CreateDate = existToken.CreateTime };
                    result.ErrorMsg = string.Empty;
                }
            }

            return result;
        }
Example #2
0
        public static AuthResult ValidateToken(string token)
        {
            AuthResult result = new AuthResult()
            {
                ErrorMsg = "Token不存在或已过期"
            };
            CacheObject co = DistributedCacheManage.GetLocalCache("tokenList");

            if (co != null)
            {
                CacheData cd = co.cacheValue.Find(x => x.key == token && x.deleteflag == false);
                if (cd != null)
                {
                    result.token    = token;
                    result.User     = JsonConvert.DeserializeObject <UserInfo>(cd.value);
                    result.ErrorMsg = string.Empty;
                }
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// 是否有效登录
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public static AuthResult ValidateToken(string token)
        {
            Guid guid = ConvertHelper.GetGuid(token, Guid.NewGuid());

            AuthResult result = new AuthResult()
            {
                ErrorMsg = "Token不存在"
            };
            TokenInfo existToken = TokenManager.GetToken(guid);

            if (existToken != null)
            {
                #region 客户端IP不一致
                //if (existToken.RemoteIp != entity.RemoteIp)
                //{
                //    result.ErrorMsg = "客户端IP不一致";
                //}
                #endregion

                if (existToken.IsValid == false)
                {
                    result.ErrorMsg = "Token已过期" + existToken.ActivityTime.ToLongTimeString() + ":" + DateTime.Now.ToLocalTime();
                    TokenManager.RemoveToken(existToken.tokenId);//移除
                }
                else
                {
                    result.User = new UserInfo()
                    {
                        UserId = existToken.UserId, UserName = existToken.UserName, CreateDate = existToken.CreateTime
                    };
                    result.ErrorMsg = string.Empty;
                }
            }

            return(result);
        }