From bd8eebcde62173fac2ddb353ba49d6b499da707a Mon Sep 17 00:00:00 2001 From: Goran Date: Tue, 20 Jan 2026 19:10:50 +0100 Subject: [PATCH] register fix --- Endpoints/UserAccess.cs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Endpoints/UserAccess.cs b/Endpoints/UserAccess.cs index 82cb57f..d46e848 100644 --- a/Endpoints/UserAccess.cs +++ b/Endpoints/UserAccess.cs @@ -68,12 +68,39 @@ public static class UserAccess private static void MapPostRegister(IEndpointRouteBuilder routes) { - routes.MapPost("/logout", async (HttpContext context) => + routes.MapPost("/register", async (HttpContext context, RegisterDto dto, AppDbContext db) => { - await context.SignOutAsync("auth"); + if (dto.Password.Length < 6) + { + context.Response.StatusCode = 400; + return; + } + + if (await db.Users.AsNoTracking().AnyAsync(u => u.Email == dto.Email)) + { + context.Response.StatusCode = 409; + return; + } + var salt = PasswordHasher.NewSalt(); + var hash = PasswordHasher.Hash(dto.Password, salt); + + var user = new User + { + Id = Guid.NewGuid().ToString(), + Email = dto.Email, + Name = "", + PasswordHash = hash, + Salt = salt, + ProfilePicture = "" + }; + + db.Users.Add(user); + await db.SaveChangesAsync(); + + context.Response.ContentType = "application/json"; context.Response.StatusCode = 200; - await context.Response.WriteAsync(""); + return; }); }