public IActionResult UpdatePassword([FromBody] UserCenterUpdatePasswordDto parm) { if (Convert.ToBoolean(AppSettings.Configuration["AppSettings:Demo"])) { ToResponse(StatusCodeType.Error, "当前为演示模式 , 您无权修改任何数据"); } var userSession = _tokenManager.GetSessionInfo(); var userInfo = _usersService.GetId(userSession.UserID); // 验证旧密码是否正确 if (!PasswordUtil.ComparePasswords(userInfo.UserID, userInfo.Password, parm.CurrentPassword.Trim())) { return(ToResponse(StatusCodeType.Error, "旧密码输入不正确")); } // 更新用户密码 var response = _usersService.Update(m => m.UserID == userInfo.UserID, m => new Sys_Users() { Password = PasswordUtil.CreateDbPassword(userInfo.UserID, parm.ConfirmPassword.Trim()) }); // 删除登录会话记录 _tokenManager.RemoveAllSession(userInfo.UserID); return(ToResponse(response)); }
public IActionResult Update([FromBody] UsersUpdateDto parm) { var userSession = _tokenManager.GetSessionInfo(); #region 更新用户信息 //判断用户是否已经存在 if (_usersService.Any(m => m.UserID == parm.UserID)) { return(toResponse(StatusCodeType.Error, $"添加 {parm.UserID} 失败,该用户已存在,不能重复!")); } #endregion var response = _usersService.Update(m => m.UserID == parm.UserID, m => new Sys_Users { UserName = parm.UserName, NickName = parm.NickName, Email = parm.Email, Sex = parm.Sex, AvatarUrl = parm.AvatarUrl, QQ = parm.QQ, Phone = parm.Phone, ProvinceID = parm.ProvinceID, Province = parm.Province, CityID = parm.CityID, City = parm.City, CountyID = parm.CountyID, County = parm.County, Address = parm.Address, Remark = parm.Remark, IdentityCard = parm.IdentityCard, Birthday = parm.Birthday, Enabled = parm.Enabled, OneSession = parm.OneSession, UpdateID = userSession.UserID, UpdateName = userSession.UserName, UpdateTime = DateTime.Now }); #region 更新登录会话记录 _tokenManager.RefreshSession(parm.UserID); #endregion return(toResponse(response)); }
/// <summary> /// 创建 Session /// </summary> public string CreateSession(Sys_Users userInfo, SourceType source, int hours) { var userSession = Guid.NewGuid().ToString().ToUpper(); //判断用户是否只允许等于一次 if (userInfo.OneSession) { RemoveAllSession(userInfo.UserID); } var expireTime = DateTime.Now.AddHours(hours); var timeSpan = new TimeSpan(hours, 0, 0); //将 Session 添加用户 Session 列表 RedisServer.Session.HSet(userInfo.UserID, userSession, expireTime); RedisServer.Session.Expire(userInfo.UserID, timeSpan); //设置 Session 信息 var userSessionVM = new UserSessionVM() { UserID = userInfo.UserID, UserName = userInfo.UserName, NickName = userInfo.NickName, Email = userInfo.Email, Sex = userInfo.Sex, AvatarUrl = userInfo.AvatarUrl, QQ = userInfo.QQ, Phone = userInfo.Phone, ProvinceID = userInfo.ProvinceID, Province = userInfo.Province, CityID = userInfo.CityID, City = userInfo.City, CountyID = userInfo.CountyID, County = userInfo.County, Address = userInfo.Address, Remark = userInfo.Remark, IdentityCard = userInfo.IdentityCard, Birthday = userInfo.Birthday, CreateTime = userInfo.CreateTime, Enabled = userInfo.Enabled, OneSession = userInfo.OneSession, Source = source.ToString(), KeepHours = hours, UserPower = _usersService.GetUserPowers(userInfo.UserID), UserRelation = _usersService.GetUserRelation(userInfo.UserID), }; RedisServer.Session.HSet(userSession, "UserInfo", userSessionVM); RedisServer.Session.Expire(userSession, timeSpan); //添加在线记录表 _onlineService.Add(new Sys_Online() { SessionID = userSession, UserID = userInfo.UserID, Source = source.ToString(), IPAddress = _accessor.HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString(), LoginTime = DateTime.Now, UpdateTime = DateTime.Now }); _usersService.Update(m => m.UserID == userInfo.UserID, m => new Sys_Users { LastLoginTime = DateTime.Now }); return(userSession); }