Skip to content

Instantly share code, notes, and snippets.

@Pownraj-2818
Created August 19, 2022 07:16
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 Pownraj-2818/a1fd91b2cb8f190083f67ff73f652ea7 to your computer and use it in GitHub Desktop.
Save Pownraj-2818/a1fd91b2cb8f190083f67ff73f652ea7 to your computer and use it in GitHub Desktop.
public async Task Verify(string otp)
{
var account = _context.Users.SingleOrDefault(x => x.OTP == otp);
if (account == null)
{
throw new BadHttpRequestException("Invalid verification OTP!");
}
if (account.VerifiedAt != DateTime.MinValue)
{
throw new BadHttpRequestException("Account already verified!");
}
account.VerifiedAt = DateTime.Now;
account.IsVerified = true;
account.OTP = null;
account.OTPExpiresAt = DateTime.MinValue;
await _context.SaveChangesAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment