public void UpdateForgottenPassword_Returns_Redirect_If_Hash_Not_Found() { var hash = "badHash"; var model = new UpdatePasswordModel { ActivationHash = hash, ActivationPin = "goodPin" }; var result = controller.UpdateForgottenPassword(hash, model); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); var message = controller.TempData["UserFeedback"]; Assert.AreEqual("The email you are looking for could not be found in our system.", message); }
public void UpdateForgottenPassword_Returns_Redirect_If_Hash_Found_And_Pins_Match() { userProfile = EntityHelpers.GetValidUserProfile(); var hash = "goodHash"; var pin = "goodPin"; userProfile.ActivationHash = hash; userProfile.ActivationPin = pin; userProfileRepository.Add(userProfile); var model = new UpdatePasswordModel { ActivationHash = hash, ActivationPin = pin, Password = "******", ConfirmPassword = "******" }; var result = controller.UpdateForgottenPassword(hash, model); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); var message = controller.TempData["UserFeedback"]; Assert.AreEqual("Sweet! Your password has been changed. You can now log in with your new password.", message); }
public ActionResult UpdatePassword(string hash) { if (User != null && !string.IsNullOrEmpty(User.Identity.Name)) { return RedirectToAction("Index", "UserProfile"); } var model = new UpdatePasswordModel { ActivationHash = hash }; return View(model); }
public void UpdateForgottenPassword_Returns_Redirect_If_Hash_Found_And_Pins_Do_Not_Match() { userProfile = EntityHelpers.GetValidUserProfile(); var hash = "goodHash"; var pin = "goodPin"; userProfile.ActivationHash = hash; userProfile.ActivationPin = pin; userProfileRepository.Add(userProfile); var model = new UpdatePasswordModel { ActivationHash = hash, ActivationPin = "badPin", Password = "******", ConfirmPassword = "******" }; var result = controller.UpdateForgottenPassword(hash, model); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); var message = controller.TempData["UserFeedback"]; Assert.IsNull(message); }
public ActionResult UpdateForgottenPassword(string hash, UpdatePasswordModel model) { if (ModelState.IsValid) { using (new UnitOfWorkScope()) { var userProfile = userProfileRepository.GetUserProfileByActivationHash(hash); var service = new GrassrootsMembershipService(); if (userProfile == null) { TempData["UserFeedback"] = "The email you are looking for could not be found in our system."; return RedirectToAction("ForgotPassword"); } if (service.UpdatePassword(userProfile, model.ActivationPin, model.Password)) { var mailModel = Mapper.Map<UserProfile, RegisterModel>(userProfile); accountMailer.PasswordChange(mailModel).SendAsync(); TempData["UserFeedback"] = "Sweet! Your password has been changed. You can now log in with your new password."; return RedirectToAction("LogOn"); } } } var activationHash = hash; return RedirectToAction("UpdatePassword", new { hash = activationHash }); }