public async Task <IActionResult> ChangePassword([FromBody] UserChangePasswordRq model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else { try { UserIdentity <int> issuer = null; issuer = GetCurrentUserIdentity <int>(); return(Ok(await _authService.ChangePasswordAsync(model, issuer))); } catch (Exception e) { return(BadRequest(e.Message)); } } }
public async Task <bool> ChangePasswordAsync(UserChangePasswordRq model, UserIdentity <int> issuer) { var user = await _userManager.FindByIdAsync(issuer.Id.ToString()); if (user == null) { return(false); } var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (!result.Succeeded) { return(false); } user.UpdateBy(issuer); await _uow.SaveChangesAsync(); await _emailService.SendEmailChangePasswordAsync(user.Email, user.UserName); return(true); }