Verification Fixes
This commit is contained in:
parent
39a1373678
commit
ce53f8dfa3
@ -48,7 +48,7 @@ namespace qtc_api.Controllers
|
|||||||
{
|
{
|
||||||
// send confirmation email (shouldn't do anything if email confirmation is disabled)
|
// send confirmation email (shouldn't do anything if email confirmation is disabled)
|
||||||
var confirmationToken = _tokenService.GenerateEmailConfirmationToken(response.Data);
|
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);
|
await _emailService.SendConfirmationEmail(response.Data.Email, response.Data.Username, confirmationUrl);
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ namespace qtc_api.Controllers
|
|||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("verify-email")]
|
[HttpGet("verify-email")]
|
||||||
public async Task<ActionResult<string>> VerifyEmail(string token)
|
public async Task<ActionResult<string>> VerifyEmail(string token)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -142,7 +142,7 @@ namespace qtc_api.Controllers
|
|||||||
if (user != null && user.Success && user.Data != null)
|
if (user != null && user.Success && user.Data != null)
|
||||||
{
|
{
|
||||||
var now = DateTime.UtcNow;
|
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;
|
user.Data.IsEmailVerified = true;
|
||||||
await dataContext.SaveChangesAsync();
|
await dataContext.SaveChangesAsync();
|
||||||
|
@ -38,20 +38,19 @@ namespace qtc_api.Services.EmailService
|
|||||||
|
|
||||||
// build confirmation email body
|
// build confirmation email body
|
||||||
StringBuilder emailBody = new();
|
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();
|
||||||
emailBody.AppendLine($"You can confirm your email by clicking here - {confirmUrl}");
|
emailBody.AppendLine($"You can confirm your email by clicking here - {confirmUrl}");
|
||||||
emailBody.AppendLine();
|
emailBody.AppendLine();
|
||||||
emailBody.AppendLine("If you did not create a QtC.NET account on any server, you may simply ignore this email.");
|
emailBody.AppendLine("If you did not create a QtC.NET account on any server, you may simply ignore this email.");
|
||||||
|
|
||||||
// create new client
|
// create new client
|
||||||
using var client = new SmtpClient()
|
using var client = new SmtpClient();
|
||||||
{
|
|
||||||
RequireTLS = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// connect and authenticate
|
// connect and authenticate
|
||||||
await client.ConnectAsync(host, 587, true);
|
await client.ConnectAsync(host, 587);
|
||||||
await client.AuthenticateAsync(username, password);
|
await client.AuthenticateAsync(username, password);
|
||||||
|
|
||||||
// construct email
|
// construct email
|
||||||
|
Loading…
x
Reference in New Issue
Block a user