Renames core domain entities and services from "User" to "Account" Refactors project-wide namespaces, classes, and database tables to use "Account" terminology Updates related components, services, and database schema to reflect new domain naming Standardizes naming conventions across authentication and organization setup features
53 lines
2 KiB
C#
53 lines
2 KiB
C#
using Insight.Database;
|
|
using Microsoft.ApplicationInsights;
|
|
using Npgsql;
|
|
using PlanTempus.Components.Accounts.Exceptions;
|
|
using PlanTempus.Core;
|
|
using PlanTempus.Core.CommandQueries;
|
|
using PlanTempus.Core.Database;
|
|
|
|
namespace PlanTempus.Components.Accounts.Create
|
|
{
|
|
public class CreateAccountHandler(
|
|
IDatabaseOperations databaseOperations,
|
|
ISecureTokenizer secureTokenizer) : ICommandHandler<CreateAccountCommand>
|
|
{
|
|
public async Task<CommandResponse> Handle(CreateAccountCommand command)
|
|
{
|
|
using var db = databaseOperations.CreateScope(nameof(CreateAccountHandler));
|
|
try
|
|
{
|
|
var sql = @"
|
|
INSERT INTO system.accounts(email , password_hash, security_stamp, email_confirmed,
|
|
access_failed_count, lockout_enabled,
|
|
is_active)
|
|
VALUES(@Email, @PasswordHash, @SecurityStamp, @EmailConfirmed,
|
|
@AccessFailedCount, @LockoutEnabled, @IsActive)
|
|
RETURNING id, created_at, email, is_active";
|
|
|
|
await db.Connection.QuerySqlAsync(sql, new
|
|
{
|
|
command.Email,
|
|
PasswordHash = secureTokenizer.TokenizeText(command.Password),
|
|
SecurityStamp = Guid.NewGuid().ToString("N"),
|
|
EmailConfirmed = false,
|
|
AccessFailedCount = 0,
|
|
LockoutEnabled = false,
|
|
command.IsActive,
|
|
});
|
|
|
|
return new CommandResponse(command.CorrelationId, command.GetType().Name, command.TransactionId);
|
|
}
|
|
catch (PostgresException ex) when (ex.SqlState == "23505" && ex.ConstraintName.Equals("accounts_email_key", StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
db.Error(ex);
|
|
throw new EmailAlreadyRegistreredException();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Error(ex);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|