public async Task<ActionResult> ResetPassword(ResetPasswordViewModel resetPasswordModel) { if (!ModelState.IsValid) return View(resetPasswordModel); if (resetPasswordModel == null) throw new HttpException(400, "Bad Request"); var user = await UserManager.FindByIdAsync(resetPasswordModel.Id); if (user == null) throw new HttpException(404, "Not Found"); await UserManager.RemovePasswordAsync(resetPasswordModel.Id); await UserManager.AddPasswordAsync(resetPasswordModel.Id, resetPasswordModel.NewPassword); TempData["Message"] = UsersMessage.ResetPasswordSuccess; TempData["UserId"] = user.Id; TempData["UserName"] = user.UserName; return RedirectToAction("index", "users"); }
public async Task<ActionResult> ResetPassword(int? id) { if (id == null) throw new HttpException(400, "Bad Request"); var user = await UserManager.FindByIdAsync(id.Value); if (user == null) throw new HttpException(404, "Not Found"); var resetPasswordViewModel = new ResetPasswordViewModel() { Id = user.Id, UserName = user.UserName, }; return View(resetPasswordViewModel); }