public async Task <ActionResult> EditPassword() { AppUser currentUser = await UserManager.FindByIdAsync(User.Identity.GetUserId <int>()); if (currentUser != null) { EditPasswordModel editPassword = new EditPasswordModel(); return(View(editPassword)); } return(RedirectToAction("Index")); }
public async Task <JsonResult> EditPassword(EditPasswordModel model) { if (!ModelState.IsValid) { return(Json(new ServiceResponse(false, ModelState.GetErrors("\n")))); } var id = User.Identity.GetUserIdInt(); var result = await UserManager.ChangePasswordAsync(id, model.CurrentPassword, model.NewPassword); return(Json(result.Succeeded ? new ServiceResponse(true, "Пароль успешно изменен") : new ServiceResponse(false, "Неверный пароль"))); }
public async Task<IActionResult> EditPassword(EditPasswordModel model) { ViewBag.Title = "设置"; if (!ModelState.IsValid) { ViewBag.PasswordResult = OperationResult.Failure(Core.Resource.Messages.ModelStateNotValid); } var result = await this.UserService.EditPassword(SecurityManager.CurrentUser.ID, model); ViewBag.PasswordResult = result; return this.View("Index"); }
public async Task <IActionResult> EditPassword(EditPasswordModel model) { ViewBag.Title = "设置"; if (!ModelState.IsValid) { ViewBag.PasswordResult = OperationResult.Failure(Core.Resource.Messages.ModelStateNotValid); } var result = await this.UserService.EditPassword(SecurityManager.CurrentUser.ID, model); ViewBag.PasswordResult = result; return(this.View("Index")); }
// #region 修改密码 public ActionResult EditPwd(EditPasswordModel model, string returnUrl) { StatusData myStatusData = new StatusData();//返回状态 // if (ModelState.IsValid) { myStatusData = myUserOptionClass.EditPwd(User.Identity.Name, model.NewPassword); ModelState.AddModelError("", myStatusData.operateMsg); } else { ModelState.AddModelError("", "填写错误。"); } return(View(model)); }
public async Task <IActionResult> UpdatePass([Bind("OldPassword, NewPassword1")] EditPasswordModel editPass) { string email = HttpContext.User.Identity.Name; var user = await _context.Users .SingleOrDefaultAsync(m => m.Email == email && m.Password == editPass.OldPassword); if (user != null) { user.Password = editPass.NewPassword1; _context.Update(user); await _context.SaveChangesAsync(); return(RedirectToAction("Logout")); } return(RedirectToAction("Details")); }
public dynamic ChangeUserPassword([FromBody] EditPasswordModel editPassword) { try { if (editPassword.password != "" || editPassword.user.userName == "") { MembershipUser user = Membership.GetUser(editPassword.user.userName); var op = user.ResetPassword(); user.ChangePassword(op, editPassword.password); return(Ok()); } throw new Exception("Password didn't math or user not found"); } catch (Exception ex) { return(ex); } }
public async Task <ActionResult> EditPassword(EditPasswordModel editModel) { AppUser currentUser = await UserManager.FindByIdAsync(User.Identity.GetUserId <int>()); if (!ModelState.IsValid) { return(View(editModel)); } IdentityResult validPass = null; if (!string.IsNullOrEmpty(editModel.NewPassword)) { if (await UserManager.CheckPasswordAsync(currentUser, editModel.OldPassword)) { validPass = await UserManager.PasswordValidator.ValidateAsync(editModel.NewPassword); if (!validPass.Succeeded) { AddErrors(validPass); } else { currentUser.Password = UserManager.PasswordHasher.HashPassword(editModel.NewPassword); IdentityResult result = await UserManager.UpdateAsync(currentUser); if (!result.Succeeded) { AddErrors(result); } else { return(RedirectToAction("Index")); } } } else { ModelState.AddModelError("", "Введен неверный пароль"); } } return(View()); }
public ActionResult EditPassword(EditPasswordModel model) { if (ModelState.IsValid) { //We need the user's current email to retrieve the account string CurrentEmail = RetrieveEmail(); //Calls UpdatePassword from the AccountProcessor class in the DatabaseBusinessLogic folder if (UpdatePassword(CurrentEmail, model.CurrentPassword, model.NewPassword) == 1) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Error updating password"); } } return(View(model)); }
public async Task <IActionResult> EditPassword(EditPasswordModel model) { ViewBag.Title = "设置"; if (!ModelState.IsValid) { ViewBag.PasswordResult = OperationResult.Failure(Core.Resource.Messages.ModelStateNotValid); } bool success = await this.UserService.EditPassword(ClientManager.CurrentUser.ID, model.OldPassword, model.NewPassword); if (success) { ViewBag.PasswordResult = new OperationResult(); } else { ViewBag.PasswordResult = OperationResult.Failure("密码错误,请确认后再试"); } return(this.View("Index")); }
public async Task <IActionResult> EditPassword(int id, EditPasswordModel user) { User newuser = await db.Users.FirstOrDefaultAsync(c => c.UserId == id); if (id != newuser.UserId) { return(NotFound()); } if (user.CurrentPassword == newuser.Password) { newuser.Password = user.Password; db.Update(newuser); await db.SaveChangesAsync(); return(RedirectToAction("Details", "Profile", new { id = id })); } else { return(View()); //return Content(newuser.Password); } }
public async Task <Result> EditPassword(long id, EditPasswordModel model) { string oldPassword = EncryptHelper.EncryptMD5(model.OldPassword); string newPassword = EncryptHelper.EncryptMD5(model.NewPassword); using (var uw = this.CreateUnitOfWork()) { var user = await uw.GetAsync <User>(t => t.ID == id && t.Password == oldPassword); if (user == null) { return(Result.ErrorResult("密码错误")); } user.Password = newPassword; await uw.UpdateAsync(user); var redis = this.RedisProvider.GetDatabase(); redis.JsonHashSet(RedisKeys.User, user.ID, user); return(Result.SuccessResult()); } }
public ActionResult EditPassword(EditPasswordModel model) { if (ModelState.IsValid) { var user = _usersRepositoryHandler.GetUserByEmail(FormsAuthentication.Decrypt (Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name); if (user == null) { return(View(model)); } user.Password = model.NewPassword; _usersRepositoryHandler.Update(user); FormsAuthentication.SignOut(); return(RedirectToAction("Login", "Account")); } else { ModelState.AddModelError("", "Неверный пароль"); } return(View(model)); }
public MResultModel ChangePassword(EditPasswordModel inputM) { MResultModel resM; try { _userBLL.ChangePassword(inputM.ID, inputM.OldPassword, inputM.NewPassword); resM = MResultModel.GetSuccessResultM("修改成功"); } catch (ApplicationException ex) { resM = MResultModel.GetFailResultM(ex.Message); } catch (ArgumentNullException ex) { resM = MResultModel.GetFailResultM(ex.Message); } catch (ArgumentException ex) { resM = MResultModel.GetFailResultM(ex.Message); } return(resM); }