// GET: UserMaintenance/ChangePassword/:{Email} public async Task <ActionResult> ChangePassword(string Email) { string code = null; try { var user = await _userManager.FindByEmailAsync(Email); if (user != null) { code = await _userManager.GeneratePasswordResetTokenAsync(user); } } catch (Exception Err) { TempData["Message"] = Err.InnerException; } if (code == null) { TempData["Message"] = "A code must be supplied for password reset."; } else { var Input = new DtoChangePassword { Code = code, Email = Email }; return(View(Input)); } return(RedirectToAction(nameof(Index))); }
public async Task ChangePasswordFromUserAccount(int id, DtoChangePassword dtoChangePassword) { await this.serviceUser.ChangePasswordFromUserAccount(id, dtoChangePassword.Password, dtoChangePassword.NewPassword); if (this.serviceUser.HasNotifications()) { this.NewNotifications(this.serviceUser.Notifications()); } await Task.CompletedTask.ConfigureAwait(false); }
public async Task <ActionResult> ChangePassword(int id, [FromBody] DtoChangePassword model) { Logger.LogInformation($"UserController.ChangePassword: PUT: api/v1/users/{id}"); await this.appServiceUser.ChangePasswordFromUserAccount(id, model); if (this.appServiceUser.HasNotifications()) { return(BadRequest(this.appServiceUser.Notifications())); } await this.appServiceUser.ChangePasswordFromUserAccount(id, model); if (this.appServiceUser.HasNotifications()) { return(BadRequest(this.appServiceUser.Notifications())); } await Task.CompletedTask.ConfigureAwait(false); return(NoContent()); }
public async Task <IActionResult> ChangePassword(string Email, [Bind("Email, Code, Password, ConfirmPassword")] DtoChangePassword dto) { if (ModelState.IsValid) { try { var user = await _userManager.FindByEmailAsync(dto.Email); if (user != null && dto.ConfirmPassword == dto.Password) { var result = await _userManager.ResetPasswordAsync(user, dto.Code, dto.Password); TempData["Message"] = user.UserName + " Password has been changed"; } } catch (Exception Err) { TempData["Message"] = Err.InnerException; } return(RedirectToAction(nameof(Index))); } return(View(dto)); }