public async Task <IActionResult> ChangePassword(int id, UserToChangePasswordDto userToChangePasswordDto) { var user = await accountManager.GetUser(id); if (await accountManager.ChangePassword(user, userToChangePasswordDto.OldPassword, userToChangePasswordDto.NewPassword)) { return(NoContent()); } return(BadRequest("Stare hasło jest niepoprawne")); }
public async Task <IActionResult> ChangePassword(int UserId, UserToChangePasswordDto userDto) { try { if (userDto == null) { return(BadRequest()); } var userFromBase = await _userManager.FindByIdAsync(UserId.ToString()); if (userFromBase == null) { return(NotFound()); } string token = Request.Headers["Authorization"]; token = token.Replace("Bearer ", ""); var result = await _signInManager.CheckPasswordSignInAsync(userFromBase, userDto.PasswordHash, false); if (!userFromBase.JsonWebToken.Equals(token) || !result.Succeeded) { return(Unauthorized()); } var resultFromChage = await _userManager.ChangePasswordAsync(userFromBase, userFromBase.PasswordHash, userDto.NewPasswordHash); // if(resultFromChage.Succeeded) // { await _signInManager.RefreshSignInAsync(userFromBase); var userToReturn = _mapper.Map <UserDto>(userFromBase); return(Created("GetUser", userToReturn)); //} //return BadRequest(); } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"DataBase is fail {ex.Message}")); } }