public async Task <IActionResult> ResetPasswordPostAsync(string username) { var user = await GetApplicationUserAsync(username); var resetToken = await userManager.GeneratePasswordResetTokenAsync(user); var newPassword = passwordGenerator.GenerateRandomPassword(); var operationResult = await userManager.ResetPasswordAsync(user, resetToken, newPassword); if (operationResult.Succeeded) { await cachedUserManager.RemoveUserByUserNameAsync(username); await emailSender.NotifyUserPasswordResetAsync(user.Email, user.UserName, newPassword); return(Ok(new ResetPasswordUsersPostResult() { NewPassword = newPassword })); } else { throw new IdentityOperationException(operationResult.Errors.Select(e => new IdentityOperationExceptionItem(e.Code, e.Description))); } }
private async Task <IActionResult> ParseIdentityResultAndReturnAsync(string username, IdentityResult operationResult) { if (operationResult.Succeeded) { await cachedUserManager.RemoveUserByUserNameAsync(username); return(NoContent()); } else { throw new IdentityOperationException(operationResult.Errors.Select(e => new IdentityOperationExceptionItem(e.Code, e.Description))); } }