public virtual ActionResult Post(UpdatePasswordForm model) { if (model == null) return HttpNotFound(); if (!ModelState.IsValid) return View(model); // get the user var user = _services.QueryProcessor.Execute( new GetUserByNameQuery { Name = User.Identity.Name, } ); // only local members can change passwords if (user.EduPersonTargetedId != null || !_services.Passwords.Exists(User.Identity.Name)) return RedirectToAction(MVC.Identity.MyHome.Get()); // update the password _services.Passwords.Update(User.Identity.Name, model.CurrentPassword, model.NewPassword); // reset the invalid password attempt window Session.FailedPasswordAttempts(false); // set feedback message SetFeedbackMessage(SuccessMessage); // redirect to return url return Redirect(model.ReturnUrl ?? Url.Action(MVC.Identity.MyHome.Get())); }
public IHttpActionResult UpdatePassword([FromBody] UpdatePasswordForm form) { Dictionary <string, string> errorList; if (!ModelState.IsValid) { errorList = AppUtils.Validation.GetErrorDictionary(ModelState); return(Content( HttpStatusCode.BadRequest, new ResponseWrapper <object>(HttpStatusCode.BadRequest, errorList) )); } uint userId = Convert.ToUInt32(RequestContext.Principal.Identity.Name); User user = new User(); if (!user.DAL_Load(userId)) { return(NotFound()); } //Later may move to its own validation that receive modelState as binding result if (!_passwordEncoder.IsMatch(form.CurrentPassword, user.Password)) { ModelState.AddModelError("CurrentPassword", "Current Password is not valid."); errorList = AppUtils.Validation.GetErrorDictionary(ModelState); return(Content( HttpStatusCode.BadRequest, new ResponseWrapper <object>(HttpStatusCode.BadRequest, errorList) )); } user.Password = _passwordEncoder.HashPassword(form.NewPassword); user.ModifiedBy = userId; if (user.DAL_UpdatePassword()) { return(Ok(new ResponseWrapper <bool>(HttpStatusCode.OK, true))); } return(InternalServerError()); }
public virtual ActionResult Get() { // get the user var user = _services.QueryProcessor.Execute( new GetUserByNameQuery { Name = User.Identity.Name, } ); // only local members can change passwords if (user.EduPersonTargetedId != null || !_services.Passwords.Exists(User.Identity.Name)) return RedirectToAction(MVC.Identity.MyHome.Get()); // create view model var model = new UpdatePasswordForm(); // return partial view return View(model); }
public virtual ActionResult Post(UpdatePasswordForm model) { if (model == null) { return(HttpNotFound()); } if (!ModelState.IsValid) { return(View(model)); } // get the user var user = _services.QueryProcessor.Execute( new GetUserByNameQuery { Name = User.Identity.Name, } ); // only local members can change passwords if (user.EduPersonTargetedId != null || !_services.Passwords.Exists(User.Identity.Name)) { return(RedirectToAction(MVC.Identity.MyHome.Get())); } // update the password _services.Passwords.Update(User.Identity.Name, model.CurrentPassword, model.NewPassword); // reset the invalid password attempt window Session.FailedPasswordAttempts(false); // set feedback message SetFeedbackMessage(SuccessMessage); // redirect to return url return(Redirect(model.ReturnUrl ?? Url.Action(MVC.Identity.MyHome.Get()))); }
public virtual ActionResult Get() { // get the user var user = _services.QueryProcessor.Execute( new GetUserByNameQuery { Name = User.Identity.Name, } ); // only local members can change passwords if (user.EduPersonTargetedId != null || !_services.Passwords.Exists(User.Identity.Name)) { return(RedirectToAction(MVC.Identity.MyHome.Get())); } // create view model var model = new UpdatePasswordForm(); // return partial view return(View(model)); }
public virtual JsonResult ValidateNewPasswordConfirmation( [CustomizeValidator(Properties = UpdatePasswordForm.NewPasswordConfirmationPropertyName)] UpdatePasswordForm model) { return(ValidateRemote(UpdatePasswordForm.NewPasswordConfirmationPropertyName)); }
public virtual JsonResult ValidateCurrentPassword( [CustomizeValidator(Properties = UpdatePasswordForm.CurrentPasswordPropertyName)] UpdatePasswordForm model) { return(ValidateRemote(UpdatePasswordForm.CurrentPasswordPropertyName)); }
public async Task <IdentityResult> asyncUpdatePassword([FromBody] UpdatePasswordForm passwordForm) { ApplicationUser user = getCurrentUser(); return(await userManager.ChangePasswordAsync(user, passwordForm.OldPassword, passwordForm.NewPassword)); }