Lock display names at registration
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user