public async Task <IActionResult> GenerateResetPasswordLink([FromBody] ResetPasswordRequestModel resetPasswordRequestModel) { try { var user = await _userManager.FindByEmailAsync(resetPasswordRequestModel.Email); if (user == null) { return(BadRequest(new ApiResponseBadRequestResult() { ErrorMessage = $"User with email { resetPasswordRequestModel.Email } does not exists" })); } var token = await _userManager.GeneratePasswordResetTokenAsync(user); var passwordResetTemplate = System.IO.File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "EmailTemplates", "password_reset_email_template.html")); byte[] tokenGeneratedBytes = Encoding.UTF8.GetBytes(token); var codeEncoded = WebEncoders.Base64UrlEncode(tokenGeneratedBytes); var emailModel = new EmailModel(); emailModel.FormPasswordResetEmailModel(user, codeEncoded, passwordResetTemplate, _configuration); await _emailService.SendEmail(emailModel); return(Ok(new ApiResponseOKResult() { Data = codeEncoded })); } catch (Exception ex) { _logger.LogError(ex, "Failed to generate password reset token"); return(StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponseFailure() { ErrorMessage = "Failed to generate password reset token" })); } }