PlanTempusApp/PlanTempus.Components/Accounts/ConfirmEmail/ConfirmEmailHandler.cs
Janus C. H. Knudsen 54b057886c Adds transactional outbox and email verification
Implements outbox pattern for reliable message delivery
Adds email verification flow with Postmark integration
Enhances account registration with secure token generation

Introduces background processing for asynchronous email sending
Implements database-level notification mechanism for message processing
2026-01-10 11:13:33 +01:00

40 lines
990 B
C#

#nullable enable
using Insight.Database;
using PlanTempus.Core.CommandQueries;
using PlanTempus.Core.Database;
namespace PlanTempus.Components.Accounts.ConfirmEmail;
public class ConfirmEmailHandler(IDatabaseOperations databaseOperations) : ICommandHandler<ConfirmEmailCommand>
{
public async Task<CommandResponse> Handle(ConfirmEmailCommand command)
{
using var db = databaseOperations.CreateScope(nameof(ConfirmEmailHandler));
var sql = @"
UPDATE system.accounts
SET email_confirmed = true
WHERE email = @Email AND security_stamp = @Token";
var affectedRows = await db.Connection.ExecuteSqlAsync(sql, new
{
command.Email,
command.Token
});
if (affectedRows == 0)
{
throw new InvalidTokenException();
}
return new CommandResponse(command.CorrelationId, command.GetType().Name, command.TransactionId);
}
}
public class InvalidTokenException : Exception
{
public InvalidTokenException() : base("Invalid or expired verification token")
{
}
}