diff --git a/qtc-net-server/Controllers/AuthController.cs b/qtc-net-server/Controllers/AuthController.cs index 2527db7..1e476d5 100644 --- a/qtc-net-server/Controllers/AuthController.cs +++ b/qtc-net-server/Controllers/AuthController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using Azure; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Razor.TagHelpers; @@ -120,13 +121,32 @@ namespace qtc_api.Controllers return Ok(response); } + [HttpPost("resend-email")] + public async Task>> ResendVerificationEmail(string email) + { + var user = await _userService.GetUserByEmail(email); + if (user != null && user.Success && user.Data != null) + { + var confirmationToken = _tokenService.GenerateEmailConfirmationToken(user.Data); + var confirmationUrl = $"{Request.Scheme}://{Request.Host}/api/auth/verify-email?token={confirmationToken.Data}"; + + await _emailService.SendConfirmationEmail(user.Data.Email, user.Data.Username, confirmationUrl); + + return Ok(new ServiceResponse { Success = true, Data = true }); + } + + return Ok(new ServiceResponse { Success = false }); + } + [HttpGet("verify-email")] public async Task> VerifyEmail(string token) { try { - var handler = new JwtSecurityTokenHandler(); - handler.InboundClaimTypeMap = new Dictionary(); + var handler = new JwtSecurityTokenHandler() + { + InboundClaimTypeMap = new Dictionary() + }; var jwt = handler.ReadJwtToken(token); diff --git a/qtc-net-server/Services/EmailService/EmailService.cs b/qtc-net-server/Services/EmailService/EmailService.cs index 1d1b106..1413950 100644 --- a/qtc-net-server/Services/EmailService/EmailService.cs +++ b/qtc-net-server/Services/EmailService/EmailService.cs @@ -38,16 +38,17 @@ namespace qtc_api.Services.EmailService // build confirmation email body StringBuilder emailBody = new(); - 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."); + emailBody.AppendLine($"

Hello {name},

"); + emailBody.AppendLine("

Your receiving this message because you made a QtC.NET Account on a server that requires email confirmation.
"); + emailBody.AppendLine(@$"You can confirm your account by clicking here.
"); + emailBody.AppendLine("NOTE: This Link Is Only Valid For 24 Hours.

"); + 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(); + using var client = new SmtpClient() + { + RequireTLS = true + }; // connect and authenticate await client.ConnectAsync(host, 587); @@ -59,7 +60,7 @@ namespace qtc_api.Services.EmailService message.From.Add(new MailboxAddress("QtC.NET Server", senderAddress)); message.Subject = emailSubject; - message.Body = new TextPart(MimeKit.Text.TextFormat.Plain) + message.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = emailBody.ToString() };