Lock display names at registration

This commit is contained in:
2026-02-06 19:36:44 +01:00
parent b88f82669b
commit 9da09315ea
6 changed files with 24 additions and 67 deletions

View File

@@ -1,8 +1,6 @@
using GameList.Contracts;
using GameList.Data;
using GameList.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;
namespace GameList.Endpoints;
@@ -101,31 +99,6 @@ public static class StateEndpoints
});
});
group.MapPost("/me/name", async ([FromBody] SetNameRequest request, HttpContext ctx, AppDbContext db) =>
{
if (request.Name.Trim().Length > 16)
{
return Results.BadRequest(new { error = "Name is required and must be <= 16 characters." });
}
var name = EndpointHelpers.TrimTo(request.Name, 16);
if (string.IsNullOrWhiteSpace(name))
{
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 = name;
await db.SaveChangesAsync();
return Results.Ok(new
{
player.Id,
player.DisplayName
});
});
}
private static Phase NextPhase(Phase current) => current switch