Ejemplo n.º 1
0
 public ActionResult ChangePassword(String userName, String statusMessage, bool success = false)
 {
     ChangePasswordModel pm = new ChangePasswordModel();
     pm.UserName = userName;
     ViewBag.success = success;
     ViewBag.StatusMessage = statusMessage;
     return View(pm);
 }
Ejemplo n.º 2
0
 public void TestChangePasswordIncorrectUserName()
 {
     ChangePasswordModel cpModel = new ChangePasswordModel();
     cpModel.UserName = "******";
     cpModel.CurrentPassword = "******";
     cpModel.NewPassword = "******";
     cpModel.NewPassword2 = "Password2!";
     ActionResult result = usersController.ChangePassword(cpModel);
     Assert.AreEqual("System.Web.Mvc.RedirectToRouteResult", result.GetType().FullName);
 }
Ejemplo n.º 3
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                MembershipUser user = Membership.GetUser(model.UserName);
                if (user != null)
                {
                    bool success = ViewBag.success = false;
                    RouteValueDictionary routes = new RouteValueDictionary();
                    routes.Add("user", model.UserName);

                    try
                    {
                        success = user.ChangePassword(model.CurrentPassword, model.NewPassword);
                    }
                    catch (PreviouslyUsedPasswordException)
                    {
                        routes.Add("statusMessage", "Your Password was not changed, please enter a new password that does not match any of the previous passwords you have used for the last 252 days.");
                    }
                    catch (ArgumentException)
                    {
                        if (!routes.ContainsKey("statusMessage"))
                        {
                            routes.Add("statusMessage", "Your Password was not changed.  Please check that the current password you have entered is correct, and enter a new password that contains a capital letter, a number, a special character, and is at least 8 characters in length.");
                        }
                    }

                    if (success && !routes.ContainsKey("statusMessage"))
                    {
                        routes.Add("statusMessage", "Your Password has been successfully changed.");
                    }
                    else if (!routes.ContainsKey("statusMessage"))
                    {
                        routes.Add("statusMessage", "Your Password was not changed, please check that the current password you have entered is correct.");
                    }
                    if (Request.IsAuthenticated)
                        return RedirectToAction("PasswordChangeConfirm", "Users", routes);
                    else
                    {
                        RouteValueDictionary routs = new RouteValueDictionary();
                        routs.Add("returnUrl", null);
                        return RedirectToAction("Login", "Users", routs);
                    }
                }
                else return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError(model.UserName, "ModelState is not valid");
                return View(model);
            }
        }
Ejemplo n.º 4
0
 public void TestChangePassword()
 {
     ChangePasswordModel cpModel = new ChangePasswordModel();
     cpModel.UserName = "******";
     cpModel.CurrentPassword = "******";
     cpModel.NewPassword = "******";
     cpModel.NewPassword2 = "Password2!";
     try
     {
         ActionResult result = usersController.ChangePassword(cpModel);
         Assert.AreEqual(0, 1);
     }
     catch (NullReferenceException e)
     {
         Assert.AreEqual(1, 1);
     }
 }