예제 #1
0
 public ActionResult ChangePassword(ChangePasswordModel model)
 {
     if (ModelState.IsValid)
     {
         if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
         {
             User user = (from a in Context.Users
                                  where a.Name == User.Identity.Name
                                  select a).SingleOrDefault();
             if (user != null)
             {
                 user.SecurityQuestion = model.SecurityQuestion;
                 user.SecurityAnswer = model.SecurityAnswer;
                 Context.SaveChanges();
                 return RedirectToAction("ChangePasswordSuccess");
             }
             ModelState.AddModelError("",
                                           string.Format(
                                               "Cannot locate the username '{0}'.  Report this error to [email protected] for assistance.",
                                               User.Identity.Name));
         }
         else
         {
             ModelState.AddModelError("",
                                           "The current password is incorrect or the new password is invalid.");
         }
     }
     return View("ChangePassword", model);
 }
예제 #2
0
 public ActionResult ChangePassword()
 {
     var model = new ChangePasswordModel
     {
         MinimumPasswordLength = MembershipService.MinPasswordLength
     };
     User user = (from a in Context.Users
                          where a.Name == User.Identity.Name
                          select a).SingleOrDefault();
     if (user == null)
         ModelState.AddModelError("", string.Format("Cannot locate the username '{0}'.  Report this error to [email protected] for assistance.", User.Identity.Name));
     else
     {
         model.SecurityAnswer = user.SecurityAnswer;
         model.SecurityQuestion = user.SecurityQuestion;
     }
     return View("ChangePassword", model);
 }