Ejemplo n.º 1
0
        /// <summary>
        /// 通过token 获取用户信息
        /// </summary>
        /// <param name="token">token</param>
        /// <param name="user"></param>
        /// <param name="isOtherWhereLogin"></param>
        /// <returns></returns>
        public bool GetUserByToken(string token, out CustomerDetail user, out bool isOtherWhereLogin)
        {
            bool isok = false;

            isOtherWhereLogin = false;
            user = null;
            //是否为被挤掉的用户
            if (!string.IsNullOrEmpty(RedisEntity.ItemGet <string>(CrowdedTokenKey + ":" + token)))
            {
                isOtherWhereLogin = true;
            }
            else
            {
                var customerId = RedisEntity.HashGet(LoginCustomerListKey, token);
                if (!string.IsNullOrEmpty(customerId))
                {
                    //获取用户信息
                    CustomerRedisDal cusRedisDal  = new CustomerRedisDal();
                    CustomerDetail   oldLoginInfo = cusRedisDal.GetCustomerDetail(long.Parse(customerId));
                    user = oldLoginInfo;
                }
                isok = true;
            }
            return(isok);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 判断是否为被挤掉的用户
        /// </summary>
        /// <param name="token">redis Key</param>
        /// <param name="deleteCrowdedToken">是否删除被挤掉的token数据</param>
        public bool IsOtherWhereLogin(string token, bool deleteCrowdedToken = false)
        {
            bool isCrowed = false;
            Guid tokenGuid;

            if (Guid.TryParse(token, out tokenGuid))
            {
                string key = CrowdedTokenKey + ":" + token;
                isCrowed = !string.IsNullOrEmpty(RedisEntity.ItemGet <string>(CrowdedTokenKey + ":" + token));

                if (isCrowed && deleteCrowdedToken)
                {
                    RedisEntity.ItemSetExpire(key, DateTime.Now.AddMinutes(5));
                }
            }
            return(isCrowed);
        }