Token fix

This commit is contained in:
dingo
2025-12-04 14:52:58 -05:00
parent 6c47ada849
commit 811b670674
3 changed files with 32 additions and 27 deletions
+22 -18
View File
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Server.Data;
using Server.Services.Auth;
using VoidScavengers.Services;
namespace VoidScavengers.Api;
@@ -73,13 +74,13 @@ public class AdminController : ControllerBase
if (!string.IsNullOrWhiteSpace(username))
query = query.Where(a => a.Username.Contains(username));
if (!string.IsNullOrWhiteSpace(email))
query = query.Where(a => a.Email != null && a.Email.Contains(email));
if (role.HasValue)
query = query.Where(a => a.Role == role.Value);
if (isBanned.HasValue)
query = query.Where(a => a.IsBanned == isBanned.Value);
@@ -131,7 +132,7 @@ public class AdminController : ControllerBase
// Permission checks
var caller = auth.Account!;
// Can't modify your own role
if (caller.Id == accountId)
return BadRequest(new { error = "Cannot modify your own role" });
@@ -152,11 +153,12 @@ public class AdminController : ControllerBase
targetAccount.Role = newRole;
await _db.SaveChangesAsync();
return Ok(new {
message = "Role updated",
accountId,
oldRole = oldRole.ToString(),
newRole = newRole.ToString()
return Ok(new
{
message = "Role updated",
accountId,
oldRole = oldRole.ToString(),
newRole = newRole.ToString()
});
}
@@ -184,15 +186,15 @@ public class AdminController : ControllerBase
return BadRequest(new { error = "Cannot ban yourself" });
targetAccount.IsBanned = true;
targetAccount.BannedUntil = request.Duration.HasValue
? DateTime.UtcNow.Add(request.Duration.Value)
targetAccount.BannedUntil = request.Duration.HasValue
? DateTime.UtcNow.Add(request.Duration.Value)
: null; // Permanent ban
// Revoke all active sessions
var activeSessions = await _db.Sessions
.Where(s => s.AccountId == accountId && s.RevokedAt == null)
.ToListAsync();
foreach (var session in activeSessions)
{
session.RevokedAt = DateTime.UtcNow;
@@ -200,9 +202,10 @@ public class AdminController : ControllerBase
await _db.SaveChangesAsync();
return Ok(new {
message = "Account banned",
accountId,
return Ok(new
{
message = "Account banned",
accountId,
bannedUntil = targetAccount.BannedUntil,
permanent = !targetAccount.BannedUntil.HasValue,
reason = request.Reason,
@@ -265,7 +268,7 @@ public class AdminController : ControllerBase
return BadRequest(new { error = "Admin accounts already exist. Use normal promotion flow." });
// Verify bootstrap key from environment
var bootstrapKey = "ThisIsThePassw0rd!";//Environment.GetEnvironmentVariable("BOOTSTRAP_ADMIN_KEY");
var bootstrapKey = Environment.GetEnvironmentVariable("BOOTSTRAP_ADMIN_KEY");
if (string.IsNullOrEmpty(bootstrapKey))
return BadRequest(new { error = "Bootstrap key not configured on server" });
@@ -283,8 +286,9 @@ public class AdminController : ControllerBase
account.Role = AccountRole.SuperAdmin;
await _db.SaveChangesAsync();
return Ok(new {
message = "SuperAdmin created successfully",
return Ok(new
{
message = "SuperAdmin created successfully",
accountId = account.Id,
username = account.Username
});