Verification Fixes

This commit is contained in:
Alan Moon 2025-07-26 16:37:39 -07:00 committed by Alan Moon
parent 4085267499
commit 503653e951
2 changed files with 8 additions and 9 deletions

View File

@ -48,7 +48,7 @@ namespace qtc_api.Controllers
{
// send confirmation email (shouldn't do anything if email confirmation is disabled)
var confirmationToken = _tokenService.GenerateEmailConfirmationToken(response.Data);
var confirmationUrl = $"{Request.Scheme}://{Request.Host}/api/auth/verify-email?token={confirmationToken}";
var confirmationUrl = $"{Request.Scheme}://{Request.Host}/api/auth/verify-email?token={confirmationToken.Data}";
await _emailService.SendConfirmationEmail(response.Data.Email, response.Data.Username, confirmationUrl);
@ -120,7 +120,7 @@ namespace qtc_api.Controllers
return Ok(response);
}
[HttpPost("verify-email")]
[HttpGet("verify-email")]
public async Task<ActionResult<string>> VerifyEmail(string token)
{
try
@ -142,7 +142,7 @@ namespace qtc_api.Controllers
if (user != null && user.Success && user.Data != null)
{
var now = DateTime.UtcNow;
if(user.Data.Email == email.Value && jwt.ValidTo.ToUniversalTime() < now)
if(user.Data.Email == email.Value && now < jwt.ValidTo.ToUniversalTime())
{
user.Data.IsEmailVerified = true;
await dataContext.SaveChangesAsync();

View File

@ -38,20 +38,19 @@ namespace qtc_api.Services.EmailService
// build confirmation email body
StringBuilder emailBody = new();
emailBody.AppendLine("Hello! This email was used to create an account on a QtC.NET Server.");
emailBody.AppendLine($"Hello {name},");
emailBody.AppendLine();
emailBody.AppendLine($"Your receiving this message because you made a QtC.NET Account on a server that requires email confirmation.");
emailBody.AppendLine();
emailBody.AppendLine($"You can confirm your email by clicking here - {confirmUrl}");
emailBody.AppendLine();
emailBody.AppendLine("If you did not create a QtC.NET account on any server, you may simply ignore this email.");
// create new client
using var client = new SmtpClient()
{
RequireTLS = true
};
using var client = new SmtpClient();
// connect and authenticate
await client.ConnectAsync(host, 587, true);
await client.ConnectAsync(host, 587);
await client.AuthenticateAsync(username, password);
// construct email