feat: email verification via smtp

This commit is contained in:
2026-03-06 20:10:07 -05:00
parent d21265f443
commit 95da3f9543
19 changed files with 773 additions and 3 deletions
@@ -27,6 +27,7 @@ namespace SharpbinV3.Server.Controllers
IOptions<AuthSettings> options,
VerificationService verification,
TotpVerificationProvider totp,
EmailService email,
AppDbContext db
) : ControllerBase
{
@@ -35,6 +36,7 @@ namespace SharpbinV3.Server.Controllers
private readonly ApiKeyService _apiKeyService = apiKeyService;
private readonly VerificationService _verification = verification;
private readonly TotpVerificationProvider _totp = totp;
private readonly EmailService _email = email;
private readonly AppDbContext _db = db;
[HttpPost]
@@ -62,6 +64,9 @@ namespace SharpbinV3.Server.Controllers
return BadRequest(new { success = false, message = "Display name should not exceed 26 characters." });
var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName);
if (!string.IsNullOrWhiteSpace(user.Email))
await _authService.SendEmailVerification(user);
return Ok(
new
{
@@ -322,5 +327,16 @@ namespace SharpbinV3.Server.Controllers
return Ok(new { success = true, message = "API key deleted." });
}
[HttpGet]
[Route("verify-email")]
public async Task<IActionResult> VerifyEmail(string token)
{
(bool verifiedEmail, string message) = await _authService.VerifyEmailVerificationToken(token);
if (verifiedEmail)
return Ok(new { success = true, message });
else
return BadRequest(new { success = false, message });
}
}
}
@@ -63,7 +63,6 @@ namespace SharpbinV3.Server.Controllers
[EnableRateLimiting("Strict")]
public async Task<IActionResult> UpdateByUUID(Guid uuid, [FromBody] UpdateUserDto updatedUser)
{
Console.WriteLine($"{ModelState.IsValid}");
if (!ModelState.IsValid)
return BadRequest(ModelState);
@@ -389,6 +388,7 @@ namespace SharpbinV3.Server.Controllers
CreatedAt = user.CreatedAt,
DisplayName = user.DisplayName,
Email = user.Email,
EmailVerified = user.EmailVerified,
LastLogin = user.LastLogin,
Roles = user.Roles,
Visibility = user.Visibility,