feat: add debug registration endpoint, fix snowflake serialization
This commit is contained in:
parent
852036a6f7
commit
588afeec20
14 changed files with 646 additions and 10 deletions
32
Foxnouns.Backend/Controllers/DebugController.cs
Normal file
32
Foxnouns.Backend/Controllers/DebugController.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using Foxnouns.Backend.Database;
|
||||
using Foxnouns.Backend.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NodaTime;
|
||||
|
||||
namespace Foxnouns.Backend.Controllers;
|
||||
|
||||
[Route("/api/v2/debug")]
|
||||
public class DebugController(DatabaseContext db, AuthService authSvc, IClock clock, ILogger logger) : ApiControllerBase
|
||||
{
|
||||
[HttpPost("users")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AuthResponse))]
|
||||
public async Task<IActionResult> CreateUser([FromBody] CreateUserRequest req)
|
||||
{
|
||||
logger.Debug("Creating user with username {Username} and email {Email}", req.Username, req.Email);
|
||||
|
||||
var user = await authSvc.CreateUserWithPasswordAsync(req.Username, req.Email, req.Password);
|
||||
var frontendApp = await db.GetFrontendApplicationAsync();
|
||||
|
||||
var (tokenStr, token) =
|
||||
authSvc.GenerateToken(user, frontendApp, ["*"], clock.GetCurrentInstant() + Duration.FromDays(365));
|
||||
db.Add(token);
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Ok(new AuthResponse(user.Id, user.Username, tokenStr));
|
||||
}
|
||||
|
||||
public record CreateUserRequest(string Username, string Password, string Email);
|
||||
|
||||
public record AuthResponse(Snowflake Id, string Username, string Token);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue