public async Task <SimpleDto <bool> > ChangePassword([FromBody] UserChangePwdInputDto inputDto) { await _accountService.UpdatePassword(inputDto, new CurrenUserInfoDto { ID = _userContext.ID, Account = _userContext.Account }); return(new SimpleDto <bool> { Result = true }); }
public async Task UpdatePassword(UserChangePwdInputDto passwordDto) { if (string.Equals(_currentUser.Account, "admin", StringComparison.OrdinalIgnoreCase)) { throw new BusinessException(new ErrorModel(ErrorCode.Forbidden, "不能修改超级管理员密码")); } if (!string.Equals(passwordDto.Password, passwordDto.RePassword)) { throw new BusinessException(new ErrorModel(ErrorCode.Forbidden, "新密码前后不一致")); } var user = await _userRepository.FetchAsync(u => new { u.ID, u.Password, u.Salt }, x => x.ID == _currentUser.ID); if (!string.Equals(HashHelper.GetHashedString(HashType.MD5, passwordDto.OldPassword, user.Salt), user.Password, StringComparison.OrdinalIgnoreCase)) { throw new BusinessException(new ErrorModel(ErrorCode.Forbidden, "旧密码输入错误")); } await _userRepository.UpdateAsync(user, p => p.Password); }
public async Task <UserValidateDto> UpdatePassword(UserChangePwdInputDto passwordDto, long userId) { var user = await _userRepository.FetchAsync(x => new { x.Password, x.Salt, x.Name, x.Email, x.RoleId, x.Account, x.ID, x.Status }, x => x.ID == userId); if (user == null) { throw new BusinessException(new ErrorModel(HttpStatusCode.NotFound, "用户不存在,参数信息不完整")); } var md5OldPwdString = HashHelper.GetHashedString(HashType.MD5, passwordDto.OldPassword, user.Salt); if (!md5OldPwdString.EqualsIgnoreCase(user.Password)) { throw new BusinessException(new ErrorModel(HttpStatusCode.Forbidden, "旧密码输入错误")); } await _userRepository.UpdateAsync(user, p => p.Password); return(_mapper.Map <UserValidateDto>(user)); }
public async Task <ActionResult> ChangePassword([FromBody] UserChangePwdInputDto inputDto) { return(Result(await _accountService.UpdatePassword(inputDto, _userContext.ID))); }
public async Task <IActionResult> ChangePassword([FromBody] UserChangePwdInputDto inputDto) { await _accountService.UpdatePassword(inputDto); return(new OkResult()); }