22 lines
No EOL
747 B
C#
22 lines
No EOL
747 B
C#
using Femto.Common.Domain;
|
|
using Femto.Modules.Auth.Application.Dto;
|
|
using Femto.Modules.Auth.Data;
|
|
using Femto.Modules.Auth.Models;
|
|
|
|
namespace Femto.Modules.Auth.Application.Commands.Register;
|
|
|
|
internal class RegisterCommandHandler(AuthContext context) : ICommandHandler<RegisterCommand, RegisterResult>
|
|
{
|
|
public async Task<RegisterResult> Handle(RegisterCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var user = new UserIdentity(request.Username);
|
|
|
|
user.SetPassword(request.Password);
|
|
|
|
var session = user.StartNewSession();
|
|
|
|
await context.AddAsync(user, cancellationToken);
|
|
|
|
return new(new Session(session.Id, session.Expires), user.Id, user.Username);
|
|
}
|
|
} |