public ActionResult ForgotPassword(ForgotPassword model) { if (ModelState.IsValid) { //get user by email address var user = Db.SingleOrDefault<User>(new { model.Email, IsDeleted = false }); //if no matching user, error if (user == null) { ModelState.AddModelErrorFor<ForgotPassword>(x => x.Email, "A user could not be found with that email address"); return View(model); } // Create token and send email var token = new PasswordRetrieval(user, Guid.NewGuid()); Db.Save(token); Metrics.Increment(Metric.Users_SendPasswordResetEmail); _mailController.ForgotPassword(new ViewModels.Mail.ForgotPassword { To = user.Email, Token = token.Token }).Deliver(); return View("ForgotPasswordConfirmation"); } return View(model); }
public void GivenValidPostRequest_SendsEmail() { var model = new ForgotPassword { Email = User.Email }; Controller.ForgotPassword(model); MailController.Verify(x => x.ForgotPassword(It.Is<ViewModels.Mail.ForgotPassword>(m => m.To == User.Email)), Times.Once()); }
public void GivenValidPostRequest_ReturnsConfirmationView() { var model = new ForgotPassword { Email = User.Email }; var result = Controller.ForgotPassword(model) as ViewResult; result.Should().Not.Be.Null(); result.ViewName.Should().Equal("ForgotPasswordConfirmation"); }
public void GivenValidPostRequest_AndNoUserWithEmail_ReturnsView() { var model = new ForgotPassword { Email = GetRandom.Email() }; var result = Controller.ForgotPassword(model) as ViewResult; result.Should().Not.Be.Null(); result.ViewName.Should().Not.Equal("ForgotPasswordConfirmation"); Controller.ModelState.Count.Should().Equal(1); }
public void GivenInvalidPostRequest_ReturnsView() { var model = new ForgotPassword { Email = GetRandom.String(20) }; Controller.ModelState.AddModelError("Email", "Email address is invalid"); var result = Controller.ForgotPassword(model) as ViewResult; result.Should().Not.Be.Null(); result.ViewName.Should().Not.Equal("ForgotPasswordConfirmation"); }