Ejemplo n.º 1
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to reset password
                ResetUserPasswordStatus resetStatus = UserAuthenticationService.GetResetPasswordToken(model.Email);

                if (resetStatus == ResetUserPasswordStatus.Success)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, AccountValidation.ResetPasswordErrorCodeToString(resetStatus));
                }
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to reset password
                ResetUserPasswordStatus resetStatus = UserAuthenticationService.GetResetPasswordToken(model.Email);

                if (resetStatus == ResetUserPasswordStatus.Success)
                {
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, AccountValidation.ResetPasswordErrorCodeToString(resetStatus));
                }
            }
            return View(model);
        }
Ejemplo n.º 3
0
        public void Reset_password_post_returns_view_if_fails()
        {
            // Arrange
            AccountController controller = GetAccountController();

            ResetPasswordModel model = new ResetPasswordModel()
            {
                Email = "wrongEmail",
            };

            // Act
            ActionResult result = controller.ResetPassword(model);

            // Assert
            var resetModel = result.AssertViewRendered().WithViewData<ResetPasswordModel>();
            Assert.AreEqual(model, resetModel);
            Assert.AreEqual("Invalid email address. Please enter a different e-mail address.", controller.ModelState[""].Errors[0].ErrorMessage);
        }
Ejemplo n.º 4
0
        public void Reset_password_post_returns_view_if_model_state_is_invalid()
        {
            // Arrange
            AccountController controller = GetAccountController();

            ResetPasswordModel model = new ResetPasswordModel()
            {
                Email = "goodEmail",
            };
            controller.ModelState.AddModelError("", "Dummy error message.");

            // Act
            ActionResult result = controller.ResetPassword(model);

            // Assert
            var resetModel = result.AssertViewRendered().WithViewData<ResetPasswordModel>();
            Assert.AreEqual(model, resetModel);
        }
Ejemplo n.º 5
0
        public void Reset_password_post_returns_redirect_on_success()
        {
            // Arrange
            AccountController controller = GetAccountController();

            ResetPasswordModel model = new ResetPasswordModel()
            {
                Email = "goodEmail",
            };

            // Act
            ActionResult result = controller.ResetPassword(model);

            // Assert
            result.AssertActionRedirect()
                .ToController("Home")
                .ToAction("Index");
        }