Beispiel #1
0
 public async Task<ActionResult> ChangePassword(ProfileChangePasswordModel model)
 {
     if (!ModelState.IsValid)
     {
         return Template(model.CreateTemplate(ControllerContext));
     }
     var db = MaintDbContext;
     var user = db.Users.FirstOrDefault(x => x.LoginName == User.Identity.Name && x.IsEnabled);
     if (user == null)
     {
         return HttpNotFound();
     }
     if (!string.Equals(user.HashPassword(model.OldPassword), user.Password, StringComparison.OrdinalIgnoreCase))
     {
         ModelState.AddModelError("OldPassword", string.Format(MaintCultureTextResources.ValidationError, MaintCultureTextResources.ProfileChangePasswordOldPassword));
         return Template(model.CreateTemplate(ControllerContext));
     }
     user.Password = user.HashPassword(model.NewPassword);
     await db.SaveChangesAsync();
     await SetFlashAsync(new FlashMessage
     {
         Text = MaintCultureTextResources.SuccessToSave,
         MessageType = FlashMessageType.Success,
     });
     return Template(model.CreateTemplate(ControllerContext));
 }
Beispiel #2
0
 public ActionResult ChangePassword()
 {
     var model = new ProfileChangePasswordModel();
     var db = MaintDbContext;
     var user = db.Users.FirstOrDefault(x => x.LoginName == User.Identity.Name);
     model.SetInnerObject(user);
     return Template(model.CreateTemplate(ControllerContext));
 }