Add CDN layer, harden admin unlock UI, scrub credentials from git
SOR.Cdn (new project):
- ICdnClient / HttpCdnClient — POST /upload?folder= + DELETE /files/{path}
- Typed HttpClient, X-Api-Key auth, 100 MB stream support
- CdnOptions: PublicBaseUrl, UploadBaseUrl, ApiKey (all via k8s env vars)
CardEditor (Assets tab):
- Upload button per asset/animation — streams file through Blazor Server SignalR
to CDN; auto-fills CdnUrl + MimeType on success
- SignalR MaximumReceiveMessageSize raised to 100 MB for large 3D model uploads
- accept="image/*" for Art2D, ".glb,.gltf,.fbx" for Model3D and animations
AccountDetail:
- Distinguish auto-lockout (≤ 1 h, yellow badge) from admin ban (> 1 h, red badge)
- "Force Unlock" clears lockout immediately + resets failed-attempt counter
- "Unban" for admin-set bans; both call SetLockoutEndDateAsync(null)
Auth lockout: 15 min → 30 min (SOR.Auth + SOR.Admin both updated)
Credentials:
- Removed hardcoded Postgres/Redis creds from all committed appsettings.json
- Production values come from k8s secret env vars (ASP.NET Core env override)
- Added appsettings.Development.json + appsettings.*.Local.json to .gitignore
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -69,14 +69,25 @@ else
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ban / Unban -->
|
||||
<!-- Account Status: covers both auto-lockout (failed attempts) and admin bans -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm @(_isBanned ? "border-danger" : "")">
|
||||
<div class="card shadow-sm @(_isRestricted ? (_isBan ? "border-danger" : "border-warning") : "")">
|
||||
<div class="card-header fw-medium d-flex justify-content-between">
|
||||
<span>Account Status</span>
|
||||
@if (_isBanned)
|
||||
@if (_isBan)
|
||||
{
|
||||
<span class="badge bg-danger">Banned until @_account.LockoutEnd?.ToString("yyyy-MM-dd")</span>
|
||||
<span class="badge bg-danger">
|
||||
Banned until @(_account.LockoutEnd!.Value == DateTimeOffset.MaxValue
|
||||
? "forever"
|
||||
: _account.LockoutEnd.Value.ToString("yyyy-MM-dd"))
|
||||
</span>
|
||||
}
|
||||
else if (_isLockedOut)
|
||||
{
|
||||
<span class="badge bg-warning text-dark">
|
||||
Locked out until @_account.LockoutEnd!.Value.ToString("HH:mm UTC")
|
||||
<small class="ms-1">(auto — failed attempts)</small>
|
||||
</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -84,11 +95,17 @@ else
|
||||
}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_isBanned)
|
||||
@if (_isRestricted)
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-success" @onclick="UnbanAsync">
|
||||
<i class="bi bi-unlock me-1"></i>Unban Account
|
||||
<button class="btn btn-sm btn-outline-success me-2" @onclick="UnlockAsync">
|
||||
<i class="bi bi-unlock me-1"></i>@(_isBan ? "Unban" : "Force Unlock")
|
||||
</button>
|
||||
@if (_isLockedOut)
|
||||
{
|
||||
<div class="form-text mt-1">
|
||||
Auto-unlocks in ~@_lockedOutMinutesLeft min. Force Unlock clears it immediately.
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -119,7 +136,10 @@ else
|
||||
|
||||
private Account? _account;
|
||||
private List<string> _roles = new();
|
||||
private bool _isBanned;
|
||||
private bool _isRestricted; // LockoutEnd is in the future (ban or auto-lockout)
|
||||
private bool _isBan; // Admin-set ban (LockoutEnd > 1 hour away)
|
||||
private bool _isLockedOut; // Auto-lockout from failed attempts (≤ 1 hour away)
|
||||
private int _lockedOutMinutesLeft;
|
||||
private int _banDays = 30;
|
||||
private string? _message;
|
||||
private bool _isError;
|
||||
@@ -130,36 +150,54 @@ else
|
||||
if (_account != null)
|
||||
{
|
||||
_roles = (await UserManager.GetRolesAsync(_account)).ToList();
|
||||
_isBanned = _account.LockoutEnd > DateTimeOffset.UtcNow;
|
||||
RefreshStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshStatus()
|
||||
{
|
||||
if (_account?.LockoutEnd is not null && _account.LockoutEnd > DateTimeOffset.UtcNow)
|
||||
{
|
||||
_isRestricted = true;
|
||||
var remaining = _account.LockoutEnd.Value - DateTimeOffset.UtcNow;
|
||||
_isLockedOut = remaining <= TimeSpan.FromHours(1);
|
||||
_isBan = !_isLockedOut;
|
||||
_lockedOutMinutesLeft = (int)Math.Ceiling(remaining.TotalMinutes);
|
||||
}
|
||||
else
|
||||
{
|
||||
_isRestricted = _isBan = _isLockedOut = false;
|
||||
_lockedOutMinutesLeft = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task BanAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
await UserManager.SetLockoutEndDateAsync(
|
||||
_account, DateTimeOffset.UtcNow.AddDays(_banDays));
|
||||
_isBanned = true;
|
||||
await UserManager.SetLockoutEnabledAsync(_account, true);
|
||||
await UserManager.SetLockoutEndDateAsync(_account, DateTimeOffset.UtcNow.AddDays(_banDays));
|
||||
_message = $"Account banned for {_banDays} days.";
|
||||
_isError = false;
|
||||
RefreshStatus();
|
||||
}
|
||||
|
||||
private async Task BanPermanentAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
await UserManager.SetLockoutEndDateAsync(
|
||||
_account, DateTimeOffset.MaxValue);
|
||||
_isBanned = true;
|
||||
await UserManager.SetLockoutEnabledAsync(_account, true);
|
||||
await UserManager.SetLockoutEndDateAsync(_account, DateTimeOffset.MaxValue);
|
||||
_message = "Account permanently banned.";
|
||||
_isError = false;
|
||||
RefreshStatus();
|
||||
}
|
||||
|
||||
private async Task UnbanAsync()
|
||||
private async Task UnlockAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
await UserManager.SetLockoutEndDateAsync(_account, null);
|
||||
_isBanned = false;
|
||||
_message = "Account unbanned.";
|
||||
await UserManager.ResetAccessFailedCountAsync(_account);
|
||||
_message = _isBan ? "Account unbanned." : "Account unlocked.";
|
||||
_isError = false;
|
||||
RefreshStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject CatalogDbContext Db
|
||||
@inject NavigationManager Nav
|
||||
@inject SOR.Cdn.ICdnClient Cdn
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
|
||||
<PageTitle>@(_isNew ? "New Card" : _card?.Name ?? "Card") – SOR Admin</PageTitle>
|
||||
|
||||
@@ -248,23 +250,51 @@ else
|
||||
else if (_activeTab == "Assets")
|
||||
{
|
||||
<h6 class="text-muted mb-3">Static Assets</h6>
|
||||
|
||||
@if (_uploadError != null)
|
||||
{
|
||||
<div class="alert alert-danger py-2">@_uploadError</div>
|
||||
}
|
||||
|
||||
<div class="row g-3 mb-4">
|
||||
@foreach (var asset in _card.Assets)
|
||||
{
|
||||
var capturedAsset = asset;
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span class="badge bg-primary">@asset.AssetType</span>
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
@onclick="() => RemoveAsset(asset)">
|
||||
@onclick="() => RemoveAsset(capturedAsset)">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
<input @bind="asset.CdnUrl" class="form-control form-control-sm"
|
||||
placeholder="https://cdn.sor.gg/…" />
|
||||
<input @bind="asset.MimeType" class="form-control form-control-sm mt-1"
|
||||
placeholder="MIME type (e.g. image/webp)" />
|
||||
<div class="input-group input-group-sm mb-1">
|
||||
<input @bind="asset.CdnUrl" class="form-control"
|
||||
placeholder="https://cdn.sor.gg/…" />
|
||||
@if (!string.IsNullOrEmpty(asset.CdnUrl))
|
||||
{
|
||||
<a href="@asset.CdnUrl" target="_blank" class="btn btn-outline-secondary">
|
||||
<i class="bi bi-box-arrow-up-right"></i>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
<input @bind="asset.MimeType" class="form-control form-control-sm mb-2"
|
||||
placeholder="MIME type (e.g. image/webp, model/gltf-binary)" />
|
||||
<label class="btn btn-sm btn-outline-primary @(_uploading.Contains(capturedAsset.Id) ? "disabled" : "")">
|
||||
@if (_uploading.Contains(capturedAsset.Id))
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm me-1"></span><span>Uploading…</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="bi bi-upload me-1"></i><span>Upload File</span>
|
||||
}
|
||||
<InputFile style="display:none"
|
||||
accept="@GetAccept(capturedAsset.AssetType)"
|
||||
OnChange="e => UploadAssetAsync(capturedAsset, e)" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -284,10 +314,11 @@ else
|
||||
|
||||
<h6 class="text-muted mb-3">Animation Bindings</h6>
|
||||
<table class="table table-sm">
|
||||
<thead><tr><th>Action</th><th>CDN URL</th><th></th></tr></thead>
|
||||
<thead><tr><th>Action</th><th>CDN URL</th><th>Upload</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var anim in _card.AnimationBindings)
|
||||
{
|
||||
var capturedAnim = anim;
|
||||
<tr>
|
||||
<td style="width:160px">
|
||||
<input @bind="anim.ActionName" class="form-control form-control-sm"
|
||||
@@ -297,9 +328,24 @@ else
|
||||
<input @bind="anim.AnimationCdnUrl" class="form-control form-control-sm"
|
||||
placeholder="https://cdn.sor.gg/…" />
|
||||
</td>
|
||||
<td style="width:110px">
|
||||
<label class="btn btn-sm btn-outline-primary @(_uploading.Contains(capturedAnim.Id) ? "disabled" : "")">
|
||||
@if (_uploading.Contains(capturedAnim.Id))
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm"></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="bi bi-upload"></i>
|
||||
}
|
||||
<InputFile style="display:none"
|
||||
accept=".glb,.gltf,.fbx"
|
||||
OnChange="e => UploadAnimationAsync(capturedAnim, e)" />
|
||||
</label>
|
||||
</td>
|
||||
<td style="width:50px">
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
@onclick="() => RemoveAnimation(anim)">
|
||||
@onclick="() => RemoveAnimation(capturedAnim)">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
@@ -325,6 +371,8 @@ else
|
||||
private bool _saveSuccess;
|
||||
private string _genusInput = string.Empty;
|
||||
private string _abilitiesJson = string.Empty;
|
||||
private readonly HashSet<Guid> _uploading = new();
|
||||
private string? _uploadError;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -441,6 +489,74 @@ else
|
||||
Db.AnimationBindings.Remove(anim);
|
||||
}
|
||||
|
||||
// ── CDN upload helpers ───────────────────────────────────────────────────
|
||||
|
||||
private async Task UploadAssetAsync(CardAsset asset, InputFileChangeEventArgs e)
|
||||
{
|
||||
_uploadError = null;
|
||||
_uploading.Add(asset.Id);
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var file = e.File;
|
||||
var folder = $"cards/{_card!.Id}/assets";
|
||||
await using var stream = file.OpenReadStream(maxAllowedSize: 100 * 1024 * 1024);
|
||||
var result = await Cdn.UploadAsync(folder, file.Name, file.ContentType, stream);
|
||||
if (result.Success)
|
||||
{
|
||||
asset.CdnUrl = result.PublicUrl ?? string.Empty;
|
||||
asset.MimeType = file.ContentType;
|
||||
}
|
||||
else
|
||||
{
|
||||
_uploadError = $"Upload failed: {result.Error}";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_uploadError = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_uploading.Remove(asset.Id);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UploadAnimationAsync(CardAnimationBinding anim, InputFileChangeEventArgs e)
|
||||
{
|
||||
_uploadError = null;
|
||||
_uploading.Add(anim.Id);
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var file = e.File;
|
||||
var folder = $"cards/{_card!.Id}/animations";
|
||||
await using var stream = file.OpenReadStream(maxAllowedSize: 100 * 1024 * 1024);
|
||||
var result = await Cdn.UploadAsync(folder, file.Name, file.ContentType, stream);
|
||||
if (result.Success)
|
||||
anim.AnimationCdnUrl = result.PublicUrl ?? string.Empty;
|
||||
else
|
||||
_uploadError = $"Upload failed: {result.Error}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_uploadError = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_uploading.Remove(anim.Id);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetAccept(CardAssetType type) => type switch
|
||||
{
|
||||
CardAssetType.Art2D => "image/*",
|
||||
CardAssetType.Model3D => ".glb,.gltf,.fbx",
|
||||
_ => "*/*",
|
||||
};
|
||||
|
||||
// ── Flag descriptors (avoids 10 identical checkboxes) ───────────────────
|
||||
|
||||
private sealed record FlagDescriptor(
|
||||
|
||||
Reference in New Issue
Block a user