public ActionResult Post(MemberPasswordResetCommand command) { try { var member = _members.FindMemberByUserName(command.UserName); member.ResetPassword(command.Password, command.Token); _session.SaveChanges(); _authentication.Login(member.Id); return RedirectToAction("Index", "Welcome"); } catch (Exception) { ModelState.AddModelError("", "Could not reset password."); return View("Get", command); } }
public void PasswordResetWorksProperly() { var authentication = new Mock<IAuthentication>(); using (var store = NewDocumentStore()) { using(var session = store.OpenSession()) { var member = new Member(); member.UserName = "******"; member.PasswordResetToken = "foo"; member.PasswordResetTokenExpiration = DateTimeOffset.UtcNow.AddMinutes(20); session.Store(member); session.SaveChanges(); } using (var session = store.OpenSession()) { var command = new MemberPasswordResetCommand { Password = "******", Token = "foo", UserName = "******" }; var members = new Mock<IFindMembers>(); members.Setup(x => x.FindMemberByUserName(It.IsAny<string>())) .Returns(session.Load<Member>(Member.FormatId(command.UserName))); var sut = new MemberPasswordResetController(session, members.Object, authentication.Object); sut.Post(command); } using (var session = store.OpenSession()) { var member = session.Load<Member>(Member.FormatId("john.doe")); Assert.IsTrue(member.VerifyPassword("a new password")); authentication.Verify(x => x.Login(Member.FormatId("john.doe")), Times.Once); } } }
public ActionResult Get(MemberPasswordResetCommand model) { return View(model); }