Limit player name lengths and fix vote UI defaults

This commit is contained in:
2026-02-02 19:39:32 +01:00
parent 1dc67879e5
commit f33545b184
11 changed files with 334 additions and 26 deletions

View File

@@ -32,15 +32,16 @@ public static class StateEndpoints
app.MapPost("/api/me/name", async ([FromBody] SetNameRequest request, HttpContext ctx, AppDbContext db) =>
{
if (string.IsNullOrWhiteSpace(request.Name) || request.Name.Length > 64)
var name = EndpointHelpers.TrimTo(request.Name, 16);
if (string.IsNullOrWhiteSpace(name))
{
return Results.BadRequest(new { error = "Name is required and must be <= 64 characters." });
return Results.BadRequest(new { error = "Name is required and must be <= 16 characters." });
}
var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db);
if (player is null) return Results.Unauthorized();
player.DisplayName = request.Name.Trim();
player.DisplayName = name;
await db.SaveChangesAsync();
return Results.Ok(new { player.Id, player.DisplayName });
});