using PyroFetes.DTO.Login.Request; using PyroFetes.DTO.Login.Response; using PasswordGenerator; namespace PyroFetes.Endpoints.Login; using FastEndpoints; public class CreateLoginEndpoint(PyroFetesDbContext database) : Endpoint { public override void Configure() { Post("/api/logins"); AllowAnonymous(); } public override async Task HandleAsync(CreateLoginDto req, CancellationToken ct) { string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next(); var login = new Models.Login() { Username = req.Username, FullName = req.FullName, Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt), Salt = salt }; database.Logins.Add(login); await database.SaveChangesAsync(ct); // Pour renvoyer une erreur : Send.StringAsync("Le message d'erreur", 400); GetLoginDto responseDto = new() { Id = login.Id, Username = login.Username, FullName = login.FullName, Password = login.Password, Salt = login.Salt }; await Send.OkAsync(responseDto, ct); } }