Email Verification And Password Reset #8
@ -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<ActionResult<ServiceResponse<bool>>> 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<bool> { Success = true, Data = true });
|
||||
}
|
||||
|
||||
return Ok(new ServiceResponse<bool> { Success = false });
|
||||
}
|
||||
|
||||
[HttpGet("verify-email")]
|
||||
public async Task<ActionResult<string>> VerifyEmail(string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
handler.InboundClaimTypeMap = new Dictionary<string, string>();
|
||||
var handler = new JwtSecurityTokenHandler()
|
||||
{
|
||||
InboundClaimTypeMap = new Dictionary<string, string>()
|
||||
};
|
||||
|
||||
var jwt = handler.ReadJwtToken(token);
|
||||
|
||||
|
@ -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($"<h1>Hello {name},</h1>");
|
||||
emailBody.AppendLine("<p>Your receiving this message because you made a QtC.NET Account on a server that requires email confirmation.<br>");
|
||||
emailBody.AppendLine(@$"You can confirm your account by clicking <a href=""{confirmUrl}"">here.</a><br>");
|
||||
emailBody.AppendLine("NOTE: This Link Is Only Valid For 24 Hours.<br><br>");
|
||||
emailBody.AppendLine("If you did not create a QtC.NET account on any server, you may simply ignore this email.</p>");
|
||||
|
||||
// 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()
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user