public async Task <IHttpActionResult> Login(LoginDTO login) { var user = await this.AccountService .LoginAsync(login.UserName, login.Password) .ConfigureAwait(true); if (user == null) { return(Ok(ResponseUtils.Converter(new object(), ResponseState.失败))); } RedisAuthorize authorize = await this.PrivilegeService .UpdateAuthorizeAsync(user) .ConfigureAwait(true); return(Ok(ResponseUtils.Converter(authorize.AuthorizeId))); }
/// <summary> /// 更新用户授权信息 /// </summary> /// <param name="user">用户</param> /// <exception cref="System.Exception">redis更新失败</exception> public RedisAuthorize UpdateAuthorize(UserInfoDTO user) { RedisAuthorize authorize = new RedisAuthorize(user); var json = JsonConvert.SerializeObject(authorize); this.DeleteAuthorize(authorize.AuthorizeId); using (var conn = this.GetRedisConn()) { var db = conn.GetDatabase(); var result = db.HashSet("MVCLearn_AuthorizeId", authorize.AuthorizeId, json); conn.Close(); if (result) { return(authorize); } throw new Exception("redis更新失败"); } }
/// <summary> /// 更新用户授权信息 /// </summary> /// <param name="user">用户</param> /// <exception cref="System.Exception">redis更新失败</exception> public async Task <RedisAuthorize> UpdateAuthorizeAsync(UserInfoDTO user) { RedisAuthorize authorize = new RedisAuthorize(user); var json = JsonConvert.SerializeObject(authorize); await this.DeleteAuthorizeAsync(authorize.AuthorizeId).ConfigureAwait(false); using (var conn = this.GetRedisConn()) { var db = conn.GetDatabase(); var result = await db.HashSetAsync("MVCLearn_AuthorizeId", authorize.AuthorizeId, json) .ConfigureAwait(false); await conn.CloseAsync().ConfigureAwait(false); if (result) { return(authorize); } throw new Exception("redis更新失败"); } }