public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model) { if (model != null) { if (ModelState.IsValid) { var userId = await _accountManager.GetUserIdByNameAsync(User.Identity.Name); (IdentityResult result, ApplicationUser user)result = await _accountManager.ChangePasswordAsync(userId, model.OldPassword, model.NewPassword); if (result.user != null) { if (result.result.Succeeded) { await SignOut(); } else { foreach (var error in result.result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } else { ModelState.AddModelError(string.Empty, ModelErrorsResource.UserNotFound); } } return(RedirectToAction("Index", "Home")); } throw new OtherException <string>(ExceptionResource.NotChanged); }
public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model) { if (ModelState.IsValid) { var userId = await _accountManager.GetUserIdByNameAsync(User.Identity.Name); var result = await _accountManager.ChangePasswordAsync(userId, model.OldPassword, model.NewPassword); if (result.Succeeded) { return(RedirectToAction("Settings", "Account")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(model)); }
public async Task <IActionResult> ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { var result = await _accountManager.ChangePasswordAsync(model); if (result.Succeeded) { ModelState.Clear(); model.IsSuccess = true; return(View(model)); } if (result.Errors?.Count() > 0) { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(View(model)); }