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())); }
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()); }