public async Task <IActionResult> EditPwd() { var utilisateur = await _userManager.GetUserAsync(User); if (utilisateur == null) { return(NotFound()); } var pwdmodel = new PwdViewModel { Password = "", ConfirmPassword = "" }; return(View(pwdmodel)); }
public async Task <IActionResult> EditPwd([Bind("Password,ConfirmPassword")] PwdViewModel pwdViewModel) { var user = await _userManager.GetUserAsync(User); if (ModelState.IsValid) { await _userManager.RemovePasswordAsync(user); var resultUserPwd = await _userManager.AddPasswordAsync(user, pwdViewModel.Password); if (resultUserPwd.Succeeded) { return(RedirectToAction(nameof(Details))); } } return(View(pwdViewModel)); }
// GET: BackOffice/Utilisateurs/Edit/5 public async Task <IActionResult> EditPwd(Guid?id) { if (id == null) { return(NotFound()); } var utilisateur = await _context.Utilisateurs.SingleOrDefaultAsync(m => m.Id == id); if (utilisateur == null) { return(NotFound()); } var pwdmodel = new PwdViewModel { Id = id.Value, Password = "", ConfirmPassword = "" }; return(View(pwdmodel)); }
public ActionResult GetPwdForm(string userId) { try { var user = UserManager.FindById(userId); if (user != null) { var model = new PwdViewModel { UserId = user.Id }; return(PartialView("_ChangePassword", model)); } } catch (Exception) { } return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> EditPwd(Guid id, [Bind("Id,Password,ConfirmPassword")] PwdViewModel pwdViewModel) { if (id != pwdViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { var user = await _userManager.Users.FirstAsync(u => u.Id == pwdViewModel.Id); await _userManager.RemovePasswordAsync(user); var resultUserPwd = await _userManager.AddPasswordAsync(user, pwdViewModel.Password); if (resultUserPwd.Succeeded) { return(RedirectToAction(nameof(Index))); } } return(View(pwdViewModel)); }
public ActionResult ChangePassword(PwdViewModel model) { if (ModelState.IsValid) { var user = UserManager.FindById(model.UserId); if (user != null) { if (user.UserName == "WcbAdmin") { ModelState.AddModelError("ChangePasswordError", "You cannot change the password for this user."); } else { UserManager.RemovePassword(user.Id); UserManager.AddPassword(user.Id, model.Password); return(Json(new { success = true })); } } } return(PartialView("_ChangePassword", model)); }