public async Task <IActionResult> ResetPasswordForLoggedInUser(ResetPasswordForLoggedInUserViewModel vm) { if (!ModelState.IsValid) { return(View()); } if (vm.NewPassword != vm.ConfirmNewPassword) { ModelState.AddModelError("", "Lösenorden matchar inte"); return(View()); } if (User.GetUserId() != vm.UserId) { ModelState.AddModelError("", "Du kan inte ändra lösenord för en annan användare"); return(View()); } var user = await _userManager.GetUserAsync(User); var result = await GenerateNewPasswordAsync(user, vm.NewPassword); if (result.Succeeded) { return(RedirectToAction("index", "profile")); } _logger.Debug("Result errors {errors}", result.Errors); return(View(vm)); }
public IActionResult ResetPasswordForLoggedInUser(string userId) { if (User.GetUserId() != userId) { return(RedirectToAction("index", "profile")); } var vm = new ResetPasswordForLoggedInUserViewModel { UserId = userId }; return(View(vm)); }