Exemplo n.º 1
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            // let's check to see if the user is allowed to change their password
            var ad = new ActiveDirectory(WebsiteUser.Username);

            if (ad.UserCannotChangePassword())
            {
                return(View("UnableToChangePassword"));
            }

            if (!ModelState.IsValid)
            {
                return(View(new ChangePasswordModel()));
            }

            try
            {
                ad.ChangePassword(model.OldPassword, model.NewPassword);
                TempData["Success"] = "Password successfully changed!";
                return(RedirectToAction("Index"));
            }
            catch (PasswordException)
            {
                ModelState.AddModelError("PasswordFailed", "Changing of your password failed. Please ensure the new password meets complexity requirements, hasn't been used previously, or if the old password does not match.");
            }

            return(View(new ChangePasswordModel()));
        }
Exemplo n.º 2
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            // let's check to see if the user is allowed to change their password
            var ad = new ActiveDirectory(WebsiteUser.Username);
            if (ad.UserCannotChangePassword()) return View("UnableToChangePassword");

            if (!ModelState.IsValid)
            {
                return View(new ChangePasswordModel());
            }

            try
            {
                ad.ChangePassword(model.OldPassword, model.NewPassword);
                TempData["Success"] = "Password successfully changed!";
                return RedirectToAction("Index");
            }
            catch (PasswordException)
            {
                ModelState.AddModelError("PasswordFailed", "Changing of your password failed. Please ensure the new password meets complexity requirements, hasn't been used previously, or if the old password does not match.");
            }

            return View(new ChangePasswordModel());
        }