public async Task <IActionResult> SetPassword(SetUserPasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var user = await _identityService.GetUser(User); var setPasswordResult = await _mediator.Send(new SetUserPasswordCommand() { User = user }); if (setPasswordResult.IdentityResult.Succeeded) { StatusMessage = "Your password has been set."; return(RedirectToAction(nameof(SetPassword))); } else { AddErrors(setPasswordResult.IdentityResult); } } catch (ValidationException ex) { AddErrors(ex); } return(View(model)); }
public async Task <IActionResult> SetPassword(string UserId, SetUserPasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.FindByIdAsync(UserId); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{UserId}'."); } var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password); if (result.Succeeded) { StatusMessage = "Password has been set."; return(RedirectToAction(nameof(SetPassword), new { @UserId = UserId })); } AddErrors(result); return(RedirectToAction(nameof(SetPassword), new { @UserId = UserId })); }
public ActionResult SetUserPassword(string UserName) { SetUserPasswordViewModel vm = new SetUserPasswordViewModel(); vm.slUsers = Utility.GetUsers(); vm.UserName = UserName; return(View(vm)); }
public ActionResult Rights_User_SetPassword(String id) { SetUserPasswordViewModel model = new SetUserPasswordViewModel { userId = id }; return(View(model)); }
public async Task <IActionResult> SetPassword(string UserId) { var user = await _userManager.FindByIdAsync(UserId); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{UserId}'."); } var code = await _userManager.GeneratePasswordResetTokenAsync(user); var model = new SetUserPasswordViewModel { StatusMessage = StatusMessage, Code = code, Email = user.Email }; return(View(model)); }
public async Task <ActionResult> ChangePassword(string Id) { ApplicationUser user = await UserManager.FindByIdAsync(Id); if (user == null || user.Email == null || user.UserName == null) { return(RedirectToAction("ErrorPage", new { msg = "Invalid Operation trying to set password." })); } SetUserPasswordViewModel model = new SetUserPasswordViewModel(); model.Id = user.Id; model.FirstName = user.FirstName; model.LastName = user.LastName; model.Email = user.Email; return(View(model)); }
public async Task <ActionResult> SetUserPassword(SetUserPasswordViewModel model) { if (ModelState.IsValid) { ApplicationUser user = UserManager.FindByName(model.UserName); string sToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var result = await UserManager.ResetPasswordAsync(user.Id, sToken, model.NewPassword); if (result.Succeeded) { return(RedirectToAction("Users", new { Message = ManageMessageId.SetPasswordSuccess })); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Rights_User_SetPassword(SetUserPasswordViewModel model) { ModelState state = ModelState["NewPassword"]; if (ModelState.IsValid) { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_identityDb)); userManager.UserValidator = new UserValidator <ApplicationUser>(userManager) { AllowOnlyAlphanumericUserNames = false }; var result2 = userManager.RemovePassword(model.userId); var result = userManager.AddPassword(model.userId, model.NewPassword); return(RedirectToAction("Rights")); } return(View()); }
public async Task <IActionResult> SetPassword() { var user = await _identityService.GetUser(User); var userHasPasswordResult = await _mediator.Send(new HasUserPasswordQuery() { User = user }); if (userHasPasswordResult.HasUserPassword) { return(RedirectToAction(nameof(ChangePassword))); } var model = new SetUserPasswordViewModel { StatusMessage = StatusMessage }; return(View(model)); }
public async Task <ActionResult> ChangePassword(SetUserPasswordViewModel model) { ApplicationUser user = await UserManager.FindByIdAsync(model.Id); if (user == null) { return(ErrorPage("Invalid Operation tryning to set password.")); } user.PasswordHash = UserManager.PasswordHasher.HashPassword(model.Password); IdentityResult result = await UserManager.UpdateAsync(user); if (!result.Succeeded) { AddErrors(result); string msg = ""; foreach (var e in result.Errors) { msg += e.ToString(); } return(ErrorPage(msg)); } else { //TODO: Notify User their email has changed - I want this to be optional //utils.EmailSender eSender = new utils.EmailSender(); //string sBody = eSender.GetNotifyMsgBody("Your account has changed for Carries Frugal Living website (CarriesFrugalLiving.com)" // , "If you received this message unexpectedly please contact us. For security reasons we will not provide a link, but simply access the main site and click Contact Us. Thank you."); //var e = eSender.Send(user.Email, "Account changed at CarriesFrugalLiving.com", sBody, true, null); //eSender = null; //if (e.Length > 0 ) //{ // ViewBag.ErrMsg = e; // to show error //} else //{ // return RedirectToAction("Index"); //} } return(RedirectToAction("Index")); }