access token generation added
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using TimetableDesigner.Backend.Events.OutboxPattern;
|
||||
using TimetableDesigner.Backend.Services.Authentication.Core.Helpers;
|
||||
using TimetableDesigner.Backend.Services.Authentication.Database;
|
||||
@@ -21,20 +22,25 @@ public class RegisterHandler : IRequestHandler<RegisterCommand, RegisterResult>
|
||||
public async Task<RegisterResult> Handle(RegisterCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
PasswordHashData hash = _passwordHasher.CreateHash(command.Password);
|
||||
|
||||
|
||||
Account account = new Account
|
||||
{
|
||||
Email = command.Email,
|
||||
Password = hash.Hash,
|
||||
PasswordSalt = hash.Salt,
|
||||
};
|
||||
await _databaseContext.Accounts.AddAsync(account, cancellationToken);
|
||||
await _databaseContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
Event eventData = Event.Create(new RegisterEvent(account.Id, account.Email));
|
||||
await _databaseContext.Events.AddAsync(eventData, cancellationToken);
|
||||
await _databaseContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
await using (IDbContextTransaction transaction = await _databaseContext.Database.BeginTransactionAsync(cancellationToken))
|
||||
{
|
||||
await _databaseContext.Accounts.AddAsync(account, cancellationToken);
|
||||
await _databaseContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
Event eventData = Event.Create(new RegisterEvent(account.Id, account.Email));
|
||||
await _databaseContext.Events.AddAsync(eventData, cancellationToken);
|
||||
await _databaseContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
await transaction.CommitAsync(cancellationToken);
|
||||
}
|
||||
|
||||
return new RegisterResult(account.Id, account.Email);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user