Add starter deck flow, admin force-logout + rename, shop flag

Auth chain:
- auth.proto: add needs_starter_deck to Login/Register/ValidateToken responses
- auth.proto: add RevokeAllSessions RPC
- AuthGrpcHandler: populate NeedsStarterDeck from Account.StarterDeckSelectedAt
- AuthGrpcHandler: track tokens in UserSessions Redis SET on create/logout
- AuthGrpcHandler: implement RevokeAllSessions (Redis + Postgres)
- IGatewayAuthValidator / GatewayAuthValidator: thread NeedsStarterDeck through tuples
- ConnectionLoop: include needsStarterDeck in auth ack payload

Client:
- Auth.gd: store needs_starter_deck from auth reply; clear on logout
- login_screen.gd: route to StarterDeckScreen when needs_starter_deck = true
- scenes/starter_deck/: new StarterDeckScreen (fetch decks → pick → confirm → InitScreen)

Admin panel:
- AccountDetail.razor: Force Logout All Sessions card (Redis + Postgres revoke)
- AccountDetail.razor: Change Display Name form with uniqueness check
- SOR.Admin: add StackExchange.Redis package + DI registration
- PrebuiltDeckEditor.razor: split into IsStarterDeck + IsAvailableInShop checkboxes
- PrebuiltDeck.cs: add IsAvailableInShop field
- Migration: AddPrebuiltDeckShopFlag

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:
dingo
2026-02-28 13:08:08 -05:00
co-authored by Claude Happy
parent fa8418387b
commit bdd6e59dfe
17 changed files with 1036 additions and 50 deletions
@@ -3,7 +3,10 @@
@inject SorIdentityDbContext Db
@inject UserManager<Account> UserManager
@inject NavigationManager Nav
@inject IConnectionMultiplexer Redis
@using Microsoft.AspNetCore.Identity
@using StackExchange.Redis
@using SOR.Shared.Redis
<PageTitle>Account – SOR Admin</PageTitle>
@@ -189,6 +192,49 @@ else
</div>
</div>
</div>
<!-- Change Display Name -->
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-header fw-medium">Change Display Name</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label small">New Display Name</label>
<input @bind="_newDisplayName" type="text" class="form-control form-control-sm"
placeholder="Unique in-game name" maxlength="32" />
</div>
<button class="btn btn-sm btn-primary" @onclick="ChangeDisplayNameAsync">
<i class="bi bi-pencil me-1"></i>Update Display Name
</button>
</div>
</div>
</div>
<!-- Force Logout -->
<div class="col-md-6">
<div class="card shadow-sm border-warning">
<div class="card-header fw-medium text-warning-emphasis">Force Logout All Sessions</div>
<div class="card-body">
<p class="text-muted small mb-3">
Revokes every active session token for this account in both Redis and
the database. The player will be disconnected immediately and must log
in again on all devices.
</p>
<button class="btn btn-sm btn-outline-danger" @onclick="ForceLogoutAsync"
disabled="@_forceLoggingOut">
@if (_forceLoggingOut)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
else
{
<i class="bi bi-box-arrow-right me-1"></i>
}
Force Logout
</button>
</div>
</div>
</div>
</div>
}
@@ -207,6 +253,8 @@ else
private string _newPassword = "";
private string _confirmPassword = "";
private string _newDisplayName = "";
private bool _forceLoggingOut;
protected override async Task OnInitializedAsync()
{
@@ -311,4 +359,77 @@ else
_isError = false;
RefreshStatus();
}
private async Task ChangeDisplayNameAsync()
{
if (_account == null) return;
var name = _newDisplayName.Trim();
if (string.IsNullOrEmpty(name))
{
_message = "Display name cannot be empty.";
_isError = true;
return;
}
var taken = await UserManager.Users.AnyAsync(u => u.DisplayName == name && u.Id != _account.Id);
if (taken)
{
_message = "That display name is already taken.";
_isError = true;
return;
}
_account.DisplayName = name;
var result = await UserManager.UpdateAsync(_account);
if (result.Succeeded)
{
_message = $"Display name changed to \"{name}\".";
_isError = false;
_newDisplayName = "";
}
else
{
_message = string.Join(" ", result.Errors.Select(e => e.Description));
_isError = true;
}
}
private async Task ForceLogoutAsync()
{
if (_account == null) return;
_forceLoggingOut = true;
try
{
var cache = Redis.GetDatabase();
var userKey = RedisKeys.UserSessions(_account.Id.ToString());
// Remove all session keys from Redis.
var members = await cache.SetMembersAsync(userKey);
foreach (var m in members)
await cache.KeyDeleteAsync(RedisKeys.Session(m!));
await cache.KeyDeleteAsync(userKey);
// Revoke all active Postgres sessions.
var now = DateTimeOffset.UtcNow;
var sessions = await Db.AccountSessions
.Where(s => s.AccountId == _account.Id && s.RevokedAt == null && s.ExpiresAt > now)
.ToListAsync();
foreach (var s in sessions)
s.RevokedAt = now;
await Db.SaveChangesAsync();
_message = $"Revoked {sessions.Count} session(s). The player has been logged out.";
_isError = false;
}
catch (Exception ex)
{
_message = $"Force logout failed: {ex.Message}";
_isError = true;
}
finally
{
_forceLoggingOut = false;
}
}
}
@@ -67,7 +67,7 @@ else
class="form-control" placeholder="—" />
</div>
</div>
<div class="col-md-4 d-flex align-items-end gap-4">
<div class="col-md-4 d-flex flex-column gap-2 justify-content-end">
<div class="form-check">
<input @bind="_deck.IsActive" type="checkbox" class="form-check-input" id="chkActive" />
<label class="form-check-label fw-medium" for="chkActive">Active</label>
@@ -75,7 +75,13 @@ else
<div class="form-check">
<input @bind="_deck.IsStarterDeck" type="checkbox" class="form-check-input" id="chkStarter" />
<label class="form-check-label fw-medium text-warning" for="chkStarter">
<i class="bi bi-star-fill me-1"></i>Starter
<i class="bi bi-star-fill me-1"></i>Offered to new accounts
</label>
</div>
<div class="form-check">
<input @bind="_deck.IsAvailableInShop" type="checkbox" class="form-check-input" id="chkShop" />
<label class="form-check-label fw-medium text-info" for="chkShop">
<i class="bi bi-shop me-1"></i>Available in shop
</label>
</div>
</div>