public async Task <IActionResult> ChangeUserPassword(string id, PasswordForChangeDto passwordForChangeDto) { var userFromRepo = await _userService.GetUserForPassChange(id, passwordForChangeDto.OldPassword); if (userFromRepo == null) { return(BadRequest(new returnMessage() { status = false, title = "خطا", message = "پسورد قبلی اشتباه میباشد" })); } if (await _userService.UpdateUserPass(userFromRepo, passwordForChangeDto.NewPassword)) { return(NoContent()); } else { return(BadRequest(new returnMessage() { status = false, title = "خطا", message = "ویرایش پسورد کاربرانجام نشد." })); } }
public async Task <IActionResult> ChangePassword(int userId, PasswordForChangeDto passwordForChangeDto) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var user = await _recipeRepo.GetUser(userId); // if (passwordForChangeDto.NewPassword != passwordForChangeDto.OldPassword) return BadRequest("Passwords do not match"); var result = await _userManager.ChangePasswordAsync(user, passwordForChangeDto.OldPassword, passwordForChangeDto.NewPassword); if (result.Succeeded) { var userToReturn = _mapper.Map <UserForDetailedDto>(user); return(Ok(new { token = GenerateJwtToken(user), user = userToReturn })); } return(Unauthorized()); }
public async Task <IActionResult> ChangeUserPassword(string id, PasswordForChangeDto passwordForChangeDto) { var userFromRepo = await _userService.GetUserForChangingPassword(id, passwordForChangeDto.OldPassword); if (userFromRepo == null) { return(BadRequest(new ReturnMessage() { Message = Resource.ErrorMessages.WrongPassword, Status = false })); } var result = await _userService.UpdateUserPassword(userFromRepo, passwordForChangeDto.NewPassword); if (result) { return(Ok(new ReturnMessage() { Message = Resource.InformationMessages.ChangedPassword, Status = true })); } else { return(BadRequest(new ReturnMessage() { Message = Resource.ErrorMessages.NoChangedPassword, Status = false })); } }
public async Task <IActionResult> ChangePassword([FromBody] PasswordForChangeDto passwordForChange) { var changedUser = await _repo.ChangePassword(passwordForChange.Username, passwordForChange.CurrentPassword, passwordForChange.NewPassword); return(Ok(changedUser)); }