public async Task <IActionResult> ResetPassword([FromQuery] string token, [FromBody] ResetPasswordResource resource) { if (ModelState.IsValid) { var user = await this.userManager.FindByEmailAsync(resource.Email); IdentityResult result = await this.userManager.ResetPasswordAsync(user, token, resource.Password); if (!result.Succeeded) { foreach (IdentityError error in result.Errors) { ModelState.AddModelError("", error.Description); } return(new BadRequestObjectResult(new BadRequestResource(ModelState))); } else { return(new OkObjectResult(new { message = "reset password has done successfully" })); } } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "Failed reset Password"); return(new BadRequestObjectResult(new BadRequestResource(ModelState))); }
public async Task <IActionResult> ResetPassword([FromBody] ResetPasswordResource resetPasswordResource) { var result = await _authService.ResetPasswordAsync(resetPasswordResource); if (!result.Succeeded) { return(BadRequest(result.ErrorMessage)); } return(Ok(result.Data)); }
public async Task <IActionResult> ResetPassword([FromBody] ResetPasswordResource resource) { var result = await _authService.ResetPasswordAsync(resource.UserId, resource.Code, resource.Password); if (!result.Succeeded) { return(BadRequest(_response.Error(result.Message))); } return(Ok(_response.Ok(result.Data))); }
public async Task <IActionResult> ResetPassword(ResetPasswordResource model) { var user = await _usersService.FindUserAsync(model.UserId); if (user == null) { return(BadRequest("NotFound")); } await _usersService.ResetPasswordAsync(user, model.NewPassword); return(Ok()); }
public async Task <GenericResponse <StatusResponse> > ResetPasswordAsync(ResetPasswordResource resource) { var user = await _userManager.FindByIdAsync(resource.UserId); if (user == null) { return new GenericResponse <StatusResponse> { Succeeded = false, ErrorMessage = "The user account does not exists" } } ; if (!await _userManager.IsEmailConfirmedAsync(user)) { return new GenericResponse <StatusResponse> { Succeeded = false, ErrorMessage = "The user account is inactive, try to confirm your email address" } } ; var result = await _userManager.ResetPasswordAsync(user, resource.Code, resource.Password); if (!result.Succeeded) { return new GenericResponse <StatusResponse> { Succeeded = false, ErrorMessage = string.Join(", ", result.Errors.Select(x => x.Description)) } } ; return(new GenericResponse <StatusResponse> { Succeeded = true, Data = new StatusResponse { Status = "The account password has been updated" } }); }
public async Task <IActionResult> ChangePasswordAsync([FromBody] ResetPasswordResource userParam) { var checkEmail = await _authService.FindByEmailAsync(userParam.Email); if (checkEmail == null) { return(BadRequest(new { message = "Email not found" })); } var userAuth = await _authService.ChangePasswordAsync(userParam.Email, userParam.Password, userParam.PasswordReset); if (userAuth == null) { return(BadRequest(new { message = "Password is incorrect" })); } var userResource = _mapper.Map <User, UserResource>(userAuth.User); return(Ok(userResource)); }
public async Task <IActionResult> ResetPassword([FromQuery] string securityCode, [FromBody] ResetPasswordResource resource) { if (ModelState.IsValid) { await _userService.ResetPasswordAsync(resource.UserName, securityCode, resource.Password); return(new OkObjectResult(new { message = "reset password has done successfully." })); } return(new BadRequestObjectResult(new { message = "Failed reset Password!" })); }