mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 15:38:45 -07:00
4edf25b2d5
Targets Rec Room 2020.12.18 client.
Re-import after adding:
- DorkNet.ClientMod/dorknet-clientmod.json.template — config schema
the launcher's manifest-driven patcher renders into UserData/.
- tools/build-patcher-zip.ps1 — produces the dorknet-clientpatch-{key}.zip
Release asset the launcher fetches.
- .github/workflows/release.yml — auto-publishes both Release assets
on v1-december-* tag push.
Scrubbed via maintainer-side scrub-for-public.ps1: same drop rules as
the prior import, plus build-patcher-zip.ps1 added to the tools/
allow-list so it survives the scrub.
55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using DorkNet.Server.Data;
|
|
using DorkNet.Server.Services;
|
|
|
|
namespace DorkNet.Server.Controllers.Admin;
|
|
|
|
/// <summary>
|
|
/// admin.rec.net/api/admin/v1/login — same-origin login endpoint for
|
|
/// the browser-based admin UI. Wraps a username+password verify
|
|
/// against PlayerEntity.PasswordHash and returns the JWT pair the UI
|
|
/// can stash in localStorage. Refuses non-admin accounts up front so a
|
|
/// regular player password can't be used to scope into the admin tools
|
|
/// even if the JWT is valid against api/admin/v1/* (the AdminOnly
|
|
/// filter would catch it anyway, but the early reject saves a
|
|
/// confused-looking 403).
|
|
///
|
|
/// Lives on admin.rec.net so the static admin page (also served from
|
|
/// admin.rec.net) can fetch with a same-origin request and skip CORS
|
|
/// entirely.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/admin/v1")]
|
|
public class AdminLoginController(
|
|
DorkNetDbContext db,
|
|
AuthService authService) : ControllerBase
|
|
{
|
|
public sealed record AdminLoginRequest(string Username, string Password);
|
|
|
|
[HttpPost("login")]
|
|
public async Task<ActionResult> Login([FromBody] AdminLoginRequest body)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(body.Username) || string.IsNullOrWhiteSpace(body.Password))
|
|
return BadRequest(new { error = "missing_credentials" });
|
|
|
|
var player = await db.Players.FirstOrDefaultAsync(p => p.Username == body.Username);
|
|
if (player is null || player.PasswordHash is null)
|
|
return Unauthorized(new { error = "invalid_credentials" });
|
|
if (!BCrypt.Net.BCrypt.Verify(body.Password, player.PasswordHash))
|
|
return Unauthorized(new { error = "invalid_credentials" });
|
|
if (!player.IsAdmin)
|
|
return StatusCode(403, new { error = "not_admin" });
|
|
|
|
var (access, refresh) = authService.GenerateTokenPair(player.Id);
|
|
return Ok(new
|
|
{
|
|
access_token = access,
|
|
refresh_token = refresh,
|
|
account_id = player.Id,
|
|
username = player.Username,
|
|
display_name = player.DisplayName,
|
|
});
|
|
}
|
|
}
|