public void UpdatePassword_Post_Returns_Redirect_When_Password_Fails() { ChangePasswordModel model = new ChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; ActionResult result = controller.UpdatePassword(model); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); Assert.IsNotNull(controller.TempData["ChangePasswordModel"]); }
public void UpdatePassword_Post_Returns_Redirect_On_Success() { ChangePasswordModel model = new ChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; ActionResult result = controller.UpdatePassword(model); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]); }
private ActionResult PasswordChangeFailed(ChangePasswordModel model) { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); TempData["ChangePasswordModel"] = model; return RedirectToAction("ChangePassword"); }
public void UpdatePassword_Post_Returns_Redirect_If_ModelState_Invalid() { ChangePasswordModel model = new ChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; controller.ModelState.AddModelError("", "Dummy error message."); ActionResult result = controller.UpdatePassword(model); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); Assert.IsNotNull(controller.TempData["ChangePasswordModel"]); }
public ActionResult SavePassword(ChangePasswordModel model, string returnUrl = "") { if (ModelState.IsValid) { using (new UnitOfWorkScope()) { var email = User.Identity.Name; var userProfile = userProfileRepository.FindUserProfileByEmail(email).FirstOrDefault(); if (userProfile == null) { return HttpNotFound("The user profile you are looking for could not be found."); } if (!MembershipService.ChangePassword(email, model.OldPassword, model.NewPassword)) { return PasswordChangeFailed(model); } var user = userProfile.Users.FirstOrDefault(); if (user != null) { user.ForcePasswordChange = false; userProfileRepository.Save(); } var mailModel = Mapper.Map<UserProfile, RegisterModel>(userProfile); accountMailer.PasswordChange(mailModel).SendAsync(); if (!string.IsNullOrEmpty(returnUrl)) { TempData["UserFeedback"] = "Thank you! Your password has been successfully updated."; return Redirect(returnUrl); } return RedirectToAction("ChangePasswordSuccess"); } } return PasswordChangeFailed(model); }