Exemple #1
0
 /// <summary>
 /// 注册
 /// </summary>
 /// <returns></returns>
 static bool Register(User user)
 {
     using (var helper = new DoRedisHash())
     {
         helper.Core.SetRangeInHash("user:"******"Tokens", user.Token, user.ID);
     }
     return(true);
 }
Exemple #2
0
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="passWord"></param>
        static string Login(string userId, string passWord)
        {
            if (IsAuth(userId, passWord))//验证密码是否正确
            {
                using (var helper = new DoRedisHash())
                {
                    //移除失效token
                    var token = helper.GetValueFromHash("user:"******"Token");
                    helper.RemoveEntryFromHash("Tokens", token);

                    token = Guid.NewGuid().ToString();
                    helper.SetEntryInHash("Tokens", token, userId);          //更新到tokens散列
                    helper.SetEntryInHash("user:"******"Token", token); //更新用户token
                    return(token);
                }
            }
            return(null);
        }
Exemple #3
0
        public string SetHash(string hashId, string key, string value)
        {
            string result = "success";

            try
            {
                DoRedisHash rh = new DoRedisHash();
                rh.SetEntryInHash(hashId, key, value);
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }