Admin portal: dark mode, account management, chat fixes, ability builder
• Light/dark mode toggle: Bootstrap 5.3 data-bs-theme, theme persisted to
localStorage via admin.js, Moon/Sun icon button in sidebar, flash-free
inline <script> in App.razor applies saved theme before first render.
• Account management: Add "Create Account" button + new /accounts/new page
(email, display name, password, role checkboxes). AccountDetail now has
interactive role assignment (Add/Remove Admin/SuperAdmin — SuperAdmin
actions gated with <AuthorizeView Roles="SuperAdmin">) and a force-reset
password section (RemovePasswordAsync + AddPasswordAsync, no current
password required).
• Chat fixes: stat card labels changed from text-muted → text-white-50 for
readability on bg-dark; card-headers now have border-bottom border-secondary
to visually separate from card bodies; "View" button relabeled "View & Post"
to surface the hidden compose feature.
• Ability builder (AbilityBuilder.razor): structured UI replacing the raw
textarea in CardEditor. Supports all 4 ability types (Active/Passive/Aura/
Triggered) with type-specific fields (range, uses/turn, aura range, trigger
dropdown). Each ability holds structured actions (scope/type/ownership/count
dropdowns) and effects (59 types in 11 grouped optgroups; each auto-populates
a JSON fields template on type selection). Description field stores plain-
English text in the JSON. Raw JSON toggle + Apply for power users. Live
compiled JSON preview.
• AbilitySystem: added JsonStringEnumConverter so JSONB enums serialize as
human-readable strings ("Active" vs 0, "Battlefield" vs 3, etc.).
• AbilityDefinition: added optional Description property (admin-only metadata).
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:
@@ -0,0 +1,130 @@
|
||||
@page "/accounts/new"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject UserManager<Account> UserManager
|
||||
@inject RoleManager<IdentityRole<Guid>> RoleManager
|
||||
@inject NavigationManager Nav
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
<PageTitle>Create Account – SOR Admin</PageTitle>
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/accounts" class="text-muted text-decoration-none small">
|
||||
<i class="bi bi-arrow-left me-1"></i>Accounts
|
||||
</a>
|
||||
<h1 class="mt-1 mb-0">Create Account</h1>
|
||||
</div>
|
||||
|
||||
@if (_message != null)
|
||||
{
|
||||
<div class="alert @(_isError ? "alert-danger" : "alert-success")">@_message</div>
|
||||
}
|
||||
|
||||
<div class="card shadow-sm" style="max-width:520px">
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Email <span class="text-danger">*</span></label>
|
||||
<input @bind="_email" type="email" class="form-control" placeholder="user@example.com" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Display Name</label>
|
||||
<input @bind="_displayName" class="form-control" placeholder="Optional" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Password <span class="text-danger">*</span></label>
|
||||
<input @bind="_password" type="password" class="form-control"
|
||||
placeholder="12+ chars, uppercase, digit, symbol" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Confirm Password <span class="text-danger">*</span></label>
|
||||
<input @bind="_confirmPassword" type="password" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Roles</label>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="roleAdmin"
|
||||
@bind="_assignAdmin" />
|
||||
<label class="form-check-label" for="roleAdmin">Admin</label>
|
||||
</div>
|
||||
<AuthorizeView Roles="SuperAdmin">
|
||||
<Authorized>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="roleSuperAdmin"
|
||||
@bind="_assignSuperAdmin" />
|
||||
<label class="form-check-label" for="roleSuperAdmin">SuperAdmin</label>
|
||||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
<button class="btn btn-primary" @onclick="CreateAsync" disabled="@_saving">
|
||||
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||
<i class="bi bi-person-check me-1"></i>Create Account
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string _email = "";
|
||||
private string _displayName = "";
|
||||
private string _password = "";
|
||||
private string _confirmPassword = "";
|
||||
private bool _assignAdmin = false;
|
||||
private bool _assignSuperAdmin = false;
|
||||
private bool _saving;
|
||||
private string? _message;
|
||||
private bool _isError;
|
||||
|
||||
private async Task CreateAsync()
|
||||
{
|
||||
_message = null;
|
||||
_isError = false;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_email))
|
||||
{
|
||||
_message = "Email is required.";
|
||||
_isError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_password))
|
||||
{
|
||||
_message = "Password is required.";
|
||||
_isError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_password != _confirmPassword)
|
||||
{
|
||||
_message = "Passwords do not match.";
|
||||
_isError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_saving = true;
|
||||
|
||||
var account = new Account
|
||||
{
|
||||
UserName = _email,
|
||||
Email = _email,
|
||||
DisplayName = string.IsNullOrWhiteSpace(_displayName) ? null : _displayName,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
var result = await UserManager.CreateAsync(account, _password);
|
||||
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
_message = string.Join(" ", result.Errors.Select(e => e.Description));
|
||||
_isError = true;
|
||||
_saving = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_assignAdmin)
|
||||
await UserManager.AddToRoleAsync(account, "Admin");
|
||||
|
||||
if (_assignSuperAdmin)
|
||||
await UserManager.AddToRoleAsync(account, "SuperAdmin");
|
||||
|
||||
Nav.NavigateTo($"/accounts/{account.Id}");
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
@inject SorIdentityDbContext Db
|
||||
@inject UserManager<Account> UserManager
|
||||
@inject NavigationManager Nav
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
<PageTitle>Account – SOR Admin</PageTitle>
|
||||
|
||||
@@ -54,17 +55,53 @@ else
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Roles</div>
|
||||
<div class="card-body">
|
||||
@if (_roles.Count == 0)
|
||||
{
|
||||
<p class="text-muted small">No roles assigned.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var role in _roles)
|
||||
<div class="mb-3">
|
||||
@if (_roles.Count == 0)
|
||||
{
|
||||
<span class="badge bg-primary me-1 mb-1">@role</span>
|
||||
<p class="text-muted small mb-2">No roles assigned.</p>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="mb-2">
|
||||
@foreach (var role in _roles)
|
||||
{
|
||||
<span class="badge bg-primary me-1 mb-1">@role</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
@if (_roles.Contains("Admin"))
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick='() => ChangeRoleAsync("Admin", false)'>
|
||||
<i class="bi bi-dash-circle me-1"></i>Remove Admin
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-primary" @onclick='() => ChangeRoleAsync("Admin", true)'>
|
||||
<i class="bi bi-plus-circle me-1"></i>Add Admin
|
||||
</button>
|
||||
}
|
||||
|
||||
<AuthorizeView Roles="SuperAdmin">
|
||||
<Authorized>
|
||||
@if (_roles.Contains("SuperAdmin"))
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick='() => ChangeRoleAsync("SuperAdmin", false)'>
|
||||
<i class="bi bi-dash-circle me-1"></i>Remove SuperAdmin
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-warning" @onclick='() => ChangeRoleAsync("SuperAdmin", true)'>
|
||||
<i class="bi bi-plus-circle me-1"></i>Add SuperAdmin
|
||||
</button>
|
||||
}
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -128,6 +165,30 @@ else
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Password Reset -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Reset Password</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-2">
|
||||
<label class="form-label small">New Password</label>
|
||||
<input @bind="_newPassword" type="password" class="form-control form-control-sm"
|
||||
placeholder="12+ chars, uppercase, digit, symbol" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small">Confirm Password</label>
|
||||
<input @bind="_confirmPassword" type="password" class="form-control form-control-sm" />
|
||||
</div>
|
||||
<button class="btn btn-sm btn-warning" @onclick="ResetPasswordAsync">
|
||||
<i class="bi bi-key me-1"></i>Force Reset Password
|
||||
</button>
|
||||
<div class="form-text mt-1">
|
||||
Bypasses current password check. The user must log in with this new password.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -136,14 +197,17 @@ else
|
||||
|
||||
private Account? _account;
|
||||
private List<string> _roles = new();
|
||||
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 bool _isRestricted;
|
||||
private bool _isBan;
|
||||
private bool _isLockedOut;
|
||||
private int _lockedOutMinutesLeft;
|
||||
private int _banDays = 30;
|
||||
private string? _message;
|
||||
private bool _isError;
|
||||
|
||||
private string _newPassword = "";
|
||||
private string _confirmPassword = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_account = await UserManager.FindByIdAsync(Id.ToString());
|
||||
@@ -171,6 +235,53 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ChangeRoleAsync(string role, bool add)
|
||||
{
|
||||
if (_account == null) return;
|
||||
if (add)
|
||||
await UserManager.AddToRoleAsync(_account, role);
|
||||
else
|
||||
await UserManager.RemoveFromRoleAsync(_account, role);
|
||||
|
||||
_roles = (await UserManager.GetRolesAsync(_account)).ToList();
|
||||
_message = add ? $"{role} role added." : $"{role} role removed.";
|
||||
_isError = false;
|
||||
}
|
||||
|
||||
private async Task ResetPasswordAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_newPassword))
|
||||
{
|
||||
_message = "New password cannot be empty.";
|
||||
_isError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_newPassword != _confirmPassword)
|
||||
{
|
||||
_message = "Passwords do not match.";
|
||||
_isError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
await UserManager.RemovePasswordAsync(_account);
|
||||
var result = await UserManager.AddPasswordAsync(_account, _newPassword);
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
_message = "Password reset successfully.";
|
||||
_isError = false;
|
||||
_newPassword = _confirmPassword = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
_message = string.Join(" ", result.Errors.Select(e => e.Description));
|
||||
_isError = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task BanAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="mb-0">Accounts</h1>
|
||||
<a href="/accounts/new" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-person-plus me-1"></i>Create Account
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-3">
|
||||
|
||||
Reference in New Issue
Block a user