Esempio 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);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取新的用户token
        /// </summary>
        /// <param name="val">用户信息</param>
        /// <returns></returns>
        public TokenOpearteResult GetNewToken(CustomerInfo val)
        {
            string customerName = val.CustomerName;
            var    oldtoken     = RedisEntity.HashGet(LoginCustomerNameListKey, customerName);

            //被挤掉的用户token
            if (!string.IsNullOrEmpty(oldtoken))
            {
                var customerId = RedisEntity.HashGet(LoginCustomerListKey, oldtoken);
                CustomerRedisDal cusRedisDal  = new CustomerRedisDal();
                CustomerDetail   oldLoginInfo = cusRedisDal.GetCustomerDetail(long.Parse(customerId));
                //不是同一台设备
                if (oldLoginInfo != null)
                {
                    //添加到被挤掉的用户
                    string crowKey = CrowdedTokenKey + ":" + oldtoken;
                    RedisEntity.ItemSet <string>(crowKey, customerName);
                    RedisEntity.ItemSetExpire(crowKey, DateTime.Now.AddDays(1));
                }
                RedisEntity.HashRemove(LoginCustomerNameListKey, customerName);
                RedisEntity.HashRemove(LoginCustomerListKey, oldtoken);
                //记录删除的token列表
                LogHelper.Debug("移除旧的token:" + oldtoken + "|" + customerName);
            }
            string token = Guid.NewGuid().ToString();

            RedisEntity.HashSet(LoginCustomerListKey, token, val.CustomerId.ToString());
            RedisEntity.HashSet(LoginCustomerNameListKey, customerName, token);
            TokenOpearteResult result = new TokenOpearteResult
            {
                isok  = true,
                token = token
            };

            return(result);
        }