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
40 lines
990 B
C#
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")
|
|
{
|
|
}
|
|
}
|