Skip to content

Instantly share code, notes, and snippets.

@DeebiKaaRaviSankar
Created August 19, 2022 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeebiKaaRaviSankar/374ad4f1674ece33d48d0e34269cae75 to your computer and use it in GitHub Desktop.
Save DeebiKaaRaviSankar/374ad4f1674ece33d48d0e34269cae75 to your computer and use it in GitHub Desktop.
[AllowAnonymous]
[HttpPost(DbConstants.Route_ForgotPassword)]
public async Task<IActionResult> ForgotPassword(EmailRequestDTO request)
{
_user = await _userRepo.GetUser(email: request.email);
if (_user == null) return BadRequest(new { error = "User not found" });
_user.ResetToken = _controllerService.GenerateOTP(_user, OTPLength: 6);
_user.ResetTokenExpires = DateTime.Now.AddMinutes(5);
_userRepo.UpdateUser(_user);
_emailContent.To = request.email;
_emailContent.Subject = "Reset your Password";
_emailContent.Body = _controllerService.OtpMailBody(_user.ResetToken, 5);
_emailService.SendEmail(_emailContent);
return Ok("Check your mail");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment