コード例 #1
0
ファイル: AccountController.cs プロジェクト: Andru91/asd
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {

                // ChangePassword will throw an exception rather
                // than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
                    changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    return RedirectToAction("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #2
0
        public void ChangePassword_Post_ReturnsRedirectOnSuccess()
        {
            // Disposizione
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };

            // Azione
            ActionResult result = controller.ChangePassword(model);

            // Asserzione
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
            Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]);
        }
コード例 #3
0
        public void ChangePassword_Post_ReturnsViewIfChangePasswordFails()
        {
            // Disposizione
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };

            // Azione
            ActionResult result = controller.ChangePassword(model);

            // Asserzione
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual("La password corrente non è corretta o la nuova password non è valida.", controller.ModelState[""].Errors[0].ErrorMessage);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: gipasoft/Sfera
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
                {
                    return RedirectToAction("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "La password corrente non è corretta o la nuova password non è valida.");
                }
            }

            // Se si arriva a questo punto, significa che si è verificato un errore, rivisualizzare il form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }
コード例 #5
0
        public void ChangePassword_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // Disposizione
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };
            controller.ModelState.AddModelError("", "Messaggio di errore fittizio.");

            // Azione
            ActionResult result = controller.ChangePassword(model);

            // Asserzione
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }