feat(website): routing fixes, login by username, leaderboard stats, news CMS, CDN art
Website fixes:
- /how-to-play and /ai-assets and /ai-assets/report: add explicit @page routes
(default Razor Pages routes were PascalCase, nav links used kebab-case)
- Webclient: redirect to webclient.aeternalisgames.com instead of /webclient/app
- Login: accept display name (username) or email; looks up by email first, then
by DisplayName — uses TUser overload of PasswordSignInAsync with lockout support
Leaderboard:
- Add GamesPlayed, GamesWon, WinRate columns
- Inject GameDbContext; query completed sessions for the top-N account IDs and
aggregate wins/plays in memory (cross-schema, no EF join)
News CMS:
- NewsPost entity in catalog schema (slug, title, summary, bodyHtml, heroImageUrl,
author, published state, timestamps)
- CatalogDbContext: add DbSet<NewsPost> + model config
- Migration: 20260423000001_AddNewsPosts
- Website Program.cs: register AddGameDatabase
- News/Index.cshtml: list published posts with hero image + summary
- News/Post.cshtml: individual post detail page at /news/{slug}
- Admin NewsPostList.razor: list all posts, delete with confirm modal
- Admin NewsPostEditor.razor: full CRUD editor — title, slug (auto from title),
summary, HTML body with live preview toggle, hero image with preview,
publish toggle + date/time, author
- Admin NavMenu: add Website section with News Posts link
CDN art:
- Index.cshtml.cs: inject IConfiguration, expose CdnBaseUrl
- Index.cshtml: add hero-bg-img <img> sourced from {cdnBase}/website/hero-bg.jpg
(upload hero-bg.jpg to CDN /website/ to activate; no image = no broken element)
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:
@@ -195,6 +195,18 @@
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/website/news" Match="NavLinkMatch.All">
|
||||
<i class="bi bi-globe me-2"></i>Website
|
||||
</NavLink>
|
||||
<ul class="nav nav-pills flex-column gap-1 ps-3 mt-1">
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white-50 py-1" href="/website/news">
|
||||
<i class="bi bi-newspaper me-2"></i>News Posts
|
||||
</NavLink>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/feature-flags">
|
||||
<i class="bi bi-toggles me-2"></i>Feature Flags
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
@page "/website/news/new"
|
||||
@page "/website/news/{PostId:guid}"
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using SOR.Database.Contexts
|
||||
@using SOR.Database.Entities.Catalog
|
||||
@inject CatalogDbContext Catalog
|
||||
@inject NavigationManager Nav
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>@(_isNew ? "New Post" : "Edit Post") — SOR Admin</PageTitle>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h3 mb-0">@(_isNew ? "New Post" : "Edit Post")</h1>
|
||||
<a href="/website/news" class="btn btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left me-1"></i>All Posts
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@if (_post is null && !_isNew)
|
||||
{
|
||||
<div class="text-muted">Loading…</div>
|
||||
}
|
||||
else if (_post is not null)
|
||||
{
|
||||
@if (!string.IsNullOrEmpty(_saveMessage))
|
||||
{
|
||||
<div class="alert alert-success alert-dismissible">
|
||||
@_saveMessage
|
||||
<button type="button" class="btn-close" @onclick="() => _saveMessage = null"></button>
|
||||
</div>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(_errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger alert-dismissible">
|
||||
@_errorMessage
|
||||
<button type="button" class="btn-close" @onclick="() => _errorMessage = null"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="row g-4">
|
||||
|
||||
<!-- ── Left column: content ──────────────────────────────────────────── -->
|
||||
<div class="col-lg-8">
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Title</label>
|
||||
<input class="form-control form-control-lg"
|
||||
@bind="_post.Title"
|
||||
@oninput="OnTitleInput"
|
||||
placeholder="Post title…" />
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">
|
||||
Summary
|
||||
<span class="text-muted fw-normal small">(shown on the news index — plain text)</span>
|
||||
</label>
|
||||
<textarea class="form-control"
|
||||
rows="2"
|
||||
@bind="_post.Summary"
|
||||
placeholder="Short teaser shown in the post list…"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span class="fw-semibold">Body (HTML)</span>
|
||||
<button class="btn btn-sm btn-outline-secondary"
|
||||
@onclick="TogglePreview">
|
||||
@(_showPreview ? "Edit" : "Preview")
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
@if (_showPreview)
|
||||
{
|
||||
<div class="p-4 prose news-post-body"
|
||||
style="min-height:300px; max-height:600px; overflow-y:auto;">
|
||||
@((MarkupString)_post.BodyHtml)
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<textarea class="form-control border-0 rounded-0 font-monospace"
|
||||
rows="20"
|
||||
style="resize:vertical; min-height:300px;"
|
||||
@bind="_post.BodyHtml"
|
||||
placeholder="<p>Write your post in HTML…</p>"></textarea>
|
||||
}
|
||||
</div>
|
||||
<div class="card-footer text-muted small">
|
||||
Supports standard HTML. Images must use absolute CDN URLs (img-src is restricted to cdn.aeternalisgames.com).
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- ── Right column: settings ────────────────────────────────────────── -->
|
||||
<div class="col-lg-4">
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header fw-semibold">Publish</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input"
|
||||
type="checkbox"
|
||||
id="published"
|
||||
@bind="_post.IsPublished"
|
||||
@oninput="OnPublishedToggle" />
|
||||
<label class="form-check-label" for="published">
|
||||
@(_post.IsPublished ? "Published" : "Draft")
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small">Publish Date / Time (UTC)</label>
|
||||
<input type="datetime-local"
|
||||
class="form-control form-control-sm"
|
||||
value="@_publishedAtLocal"
|
||||
@onchange="OnPublishedAtChanged" />
|
||||
<div class="form-text">Leave blank to publish immediately when toggled on.</div>
|
||||
</div>
|
||||
<button class="btn btn-primary w-100" @onclick="SaveAsync" disabled="@_saving">
|
||||
@(_saving ? "Saving…" : "Save")
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header fw-semibold">Meta</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Slug</label>
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text text-muted">/news/</span>
|
||||
<input class="form-control"
|
||||
@bind="_post.Slug"
|
||||
placeholder="my-post-slug" />
|
||||
</div>
|
||||
<div class="form-text">URL-safe, lowercase, hyphens only. Auto-generated from title.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Author</label>
|
||||
<input class="form-control form-control-sm"
|
||||
@bind="_post.AuthorName"
|
||||
placeholder="Aeternalis Games" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header fw-semibold">Hero Image</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small">CDN URL</label>
|
||||
<input class="form-control form-control-sm"
|
||||
@bind="_post.HeroImageUrl"
|
||||
placeholder="https://cdn.aeternalisgames.com/…" />
|
||||
</div>
|
||||
@if (!string.IsNullOrWhiteSpace(_post.HeroImageUrl))
|
||||
{
|
||||
<img src="@_post.HeroImageUrl"
|
||||
alt="Hero preview"
|
||||
class="img-fluid rounded"
|
||||
style="max-height:160px; object-fit:cover;" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid? PostId { get; set; }
|
||||
|
||||
private NewsPost? _post;
|
||||
private bool _isNew;
|
||||
private bool _showPreview;
|
||||
private bool _saving;
|
||||
private string? _saveMessage;
|
||||
private string? _errorMessage;
|
||||
private string _publishedAtLocal = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (PostId is null)
|
||||
{
|
||||
_isNew = true;
|
||||
_post = new NewsPost
|
||||
{
|
||||
AuthorName = "Aeternalis Games",
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
_post = await Catalog.NewsPosts.FindAsync(PostId.Value);
|
||||
if (_post?.PublishedAt is not null)
|
||||
_publishedAtLocal = _post.PublishedAt.Value.UtcDateTime.ToString("yyyy-MM-ddTHH:mm");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTitleInput(ChangeEventArgs e)
|
||||
{
|
||||
var title = e.Value?.ToString() ?? string.Empty;
|
||||
_post!.Title = title;
|
||||
|
||||
// Auto-generate slug only if still empty or matches old auto-generated value.
|
||||
if (_isNew || string.IsNullOrWhiteSpace(_post.Slug))
|
||||
_post.Slug = Slugify(title);
|
||||
}
|
||||
|
||||
private void OnPublishedToggle(ChangeEventArgs e)
|
||||
{
|
||||
if (_post is null) return;
|
||||
var on = e.Value is bool b && b;
|
||||
if (on && _post.PublishedAt is null)
|
||||
{
|
||||
_post.PublishedAt = DateTimeOffset.UtcNow;
|
||||
_publishedAtLocal = _post.PublishedAt.Value.UtcDateTime.ToString("yyyy-MM-ddTHH:mm");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPublishedAtChanged(ChangeEventArgs e)
|
||||
{
|
||||
if (_post is null) return;
|
||||
if (DateTime.TryParse(e.Value?.ToString(), out var dt))
|
||||
{
|
||||
_post.PublishedAt = new DateTimeOffset(dt, TimeSpan.Zero);
|
||||
_publishedAtLocal = dt.ToString("yyyy-MM-ddTHH:mm");
|
||||
}
|
||||
else
|
||||
{
|
||||
_post.PublishedAt = null;
|
||||
_publishedAtLocal = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void TogglePreview() => _showPreview = !_showPreview;
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (_post is null) return;
|
||||
_saving = true;
|
||||
_saveMessage = null;
|
||||
_errorMessage = null;
|
||||
|
||||
try
|
||||
{
|
||||
_post.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
|
||||
if (_isNew)
|
||||
{
|
||||
Catalog.NewsPosts.Add(_post);
|
||||
await Catalog.SaveChangesAsync();
|
||||
_isNew = false;
|
||||
Nav.NavigateTo($"/website/news/{_post.Id}", replace: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Catalog.NewsPosts.Update(_post);
|
||||
await Catalog.SaveChangesAsync();
|
||||
}
|
||||
|
||||
_saveMessage = "Post saved.";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_errorMessage = $"Save failed: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
_saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string Slugify(string title)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(title)) return string.Empty;
|
||||
return System.Text.RegularExpressions.Regex
|
||||
.Replace(title.ToLowerInvariant().Trim(), @"[^a-z0-9]+", "-")
|
||||
.Trim('-');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
@page "/website/news"
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using SOR.Database.Contexts
|
||||
@using SOR.Database.Entities.Catalog
|
||||
@inject CatalogDbContext Catalog
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>News Posts — SOR Admin</PageTitle>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h3 mb-0">News Posts</h1>
|
||||
<a href="/website/news/new" class="btn btn-primary">
|
||||
<i class="bi bi-plus-lg me-1"></i>New Post
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@if (_posts is null)
|
||||
{
|
||||
<div class="text-muted">Loading…</div>
|
||||
}
|
||||
else if (_posts.Count == 0)
|
||||
{
|
||||
<div class="alert alert-info">No posts yet. Create one to get started.</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-hover align-middle">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Slug</th>
|
||||
<th>Author</th>
|
||||
<th>Status</th>
|
||||
<th>Published</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var post in _posts)
|
||||
{
|
||||
<tr>
|
||||
<td><strong>@post.Title</strong></td>
|
||||
<td><code class="small">/news/@post.Slug</code></td>
|
||||
<td>@post.AuthorName</td>
|
||||
<td>
|
||||
@if (post.IsPublished)
|
||||
{
|
||||
<span class="badge bg-success">Published</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-secondary">Draft</span>
|
||||
}
|
||||
</td>
|
||||
<td class="text-muted small">
|
||||
@(post.PublishedAt?.ToString("yyyy-MM-dd") ?? "—")
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<a href="/website/news/@post.Id" class="btn btn-sm btn-outline-primary me-1">
|
||||
<i class="bi bi-pencil me-1"></i>Edit
|
||||
</a>
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
@onclick="() => ConfirmDelete(post)">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@if (_deleteTarget is not null)
|
||||
{
|
||||
<div class="modal show d-block" tabindex="-1" style="background:rgba(0,0,0,.5)">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Delete Post</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Delete <strong>@_deleteTarget.Title</strong>? This cannot be undone.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" @onclick="CancelDelete">Cancel</button>
|
||||
<button class="btn btn-danger" @onclick="ExecuteDelete">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<NewsPost>? _posts;
|
||||
private NewsPost? _deleteTarget;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
_posts = await Catalog.NewsPosts
|
||||
.OrderByDescending(p => p.CreatedAt)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private void ConfirmDelete(NewsPost post) => _deleteTarget = post;
|
||||
private void CancelDelete() => _deleteTarget = null;
|
||||
|
||||
private async Task ExecuteDelete()
|
||||
{
|
||||
if (_deleteTarget is null) return;
|
||||
Catalog.NewsPosts.Remove(_deleteTarget);
|
||||
await Catalog.SaveChangesAsync();
|
||||
_deleteTarget = null;
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public sealed class CatalogDbContext : DbContext
|
||||
public CatalogDbContext(DbContextOptions<CatalogDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<NewsPost> NewsPosts => Set<NewsPost>();
|
||||
public DbSet<CardSet> CardSets => Set<CardSet>();
|
||||
public DbSet<CardDefinition> CardDefinitions => Set<CardDefinition>();
|
||||
public DbSet<CardAsset> CardAssets => Set<CardAsset>();
|
||||
@@ -36,6 +37,17 @@ public sealed class CatalogDbContext : DbContext
|
||||
{
|
||||
builder.HasDefaultSchema("catalog");
|
||||
|
||||
builder.Entity<NewsPost>(e =>
|
||||
{
|
||||
e.ToTable("news_posts");
|
||||
e.HasKey(n => n.Id);
|
||||
e.Property(n => n.Slug).IsRequired();
|
||||
e.Property(n => n.Title).IsRequired();
|
||||
e.Property(n => n.BodyHtml).HasColumnType("text").IsRequired();
|
||||
e.HasIndex(n => n.Slug).IsUnique();
|
||||
e.HasIndex(n => new { n.IsPublished, n.PublishedAt });
|
||||
});
|
||||
|
||||
builder.Entity<CardSet>(e =>
|
||||
{
|
||||
e.ToTable("card_sets");
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
/// <summary>
|
||||
/// A website news post / announcement managed via the admin portal.
|
||||
///
|
||||
/// Body content is stored as HTML — the admin editor is responsible for
|
||||
/// sanitising or producing safe markup before saving.
|
||||
/// </summary>
|
||||
public sealed class NewsPost
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>URL-friendly slug, e.g. "set-2-launch". Must be unique.</summary>
|
||||
public string Slug { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Display title of the post.</summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Short teaser shown on the news index page (plain text).</summary>
|
||||
public string Summary { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Full post body as HTML. Rendered directly — admin is trusted.</summary>
|
||||
public string BodyHtml { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>CDN URL of the post's hero image. Null = no image.</summary>
|
||||
public string? HeroImageUrl { get; set; }
|
||||
|
||||
/// <summary>Author display name shown on the post.</summary>
|
||||
public string AuthorName { get; set; } = "Aeternalis Games";
|
||||
|
||||
/// <summary>When the post was made visible. Null = not yet published.</summary>
|
||||
public DateTimeOffset? PublishedAt { get; set; }
|
||||
|
||||
/// <summary>True once PublishedAt is set and the post is live.</summary>
|
||||
public bool IsPublished { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Catalog
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddNewsPosts : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "news_posts",
|
||||
schema: "catalog",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Slug = table.Column<string>(type: "text", nullable: false),
|
||||
Title = table.Column<string>(type: "text", nullable: false),
|
||||
Summary = table.Column<string>(type: "text", nullable: false),
|
||||
BodyHtml = table.Column<string>(type: "text", nullable: false),
|
||||
HeroImageUrl = table.Column<string>(type: "text", nullable: true),
|
||||
AuthorName = table.Column<string>(type: "text", nullable: false),
|
||||
PublishedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
IsPublished = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_news_posts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_news_posts_Slug",
|
||||
schema: "catalog",
|
||||
table: "news_posts",
|
||||
column: "Slug",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_news_posts_IsPublished_PublishedAt",
|
||||
schema: "catalog",
|
||||
table: "news_posts",
|
||||
columns: new[] { "IsPublished", "PublishedAt" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "news_posts",
|
||||
schema: "catalog");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@page
|
||||
@page "/ai-assets"
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "AI Asset Disclosure";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@page
|
||||
@page "/ai-assets/report"
|
||||
@model ReportModel
|
||||
@{
|
||||
ViewData["Title"] = "AI Asset Report";
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
<input type="hidden" asp-for="ReturnUrl">
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.Email">Email</label>
|
||||
<input asp-for="Input.Email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
<label asp-for="Input.UsernameOrEmail">Username or Email</label>
|
||||
<input asp-for="Input.UsernameOrEmail"
|
||||
type="text"
|
||||
autocomplete="username"
|
||||
autofocus
|
||||
class="form-control"
|
||||
placeholder="you@example.com">
|
||||
<span asp-validation-for="Input.Email" class="field-error"></span>
|
||||
placeholder="your handle or email">
|
||||
<span asp-validation-for="Input.UsernameOrEmail" class="field-error"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
@@ -38,10 +39,10 @@ public sealed class LoginModel(
|
||||
|
||||
public sealed class InputModel
|
||||
{
|
||||
[Required(ErrorMessage = "Email is required.")]
|
||||
[EmailAddress(ErrorMessage = "Enter a valid email address.")]
|
||||
// Accepts either an email address or the player's in-game display name (handle).
|
||||
[Required(ErrorMessage = "Username or email is required.")]
|
||||
[MaxLength(254)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string UsernameOrEmail { get; set; } = string.Empty;
|
||||
|
||||
[Required(ErrorMessage = "Password is required.")]
|
||||
[DataType(DataType.Password)]
|
||||
@@ -65,40 +66,44 @@ public sealed class LoginModel(
|
||||
if (!ModelState.IsValid)
|
||||
return Page();
|
||||
|
||||
// PasswordSignInAsync with lockoutOnFailure:true — after 5 failures the
|
||||
// account is locked for 30 minutes (configured in Program.cs).
|
||||
var result = await signInManager.PasswordSignInAsync(
|
||||
Input.Email,
|
||||
Input.Password,
|
||||
Input.RememberMe,
|
||||
lockoutOnFailure: true);
|
||||
// Resolve account: try email first, then fall back to display name.
|
||||
// We look up the user explicitly so we can use the TUser overload of
|
||||
// PasswordSignInAsync — this lets us pass lockoutOnFailure correctly
|
||||
// regardless of which identifier the player used.
|
||||
var input = Input.UsernameOrEmail.Trim();
|
||||
var user = await userManager.FindByEmailAsync(input)
|
||||
?? await userManager.Users
|
||||
.FirstOrDefaultAsync(u => u.DisplayName == input);
|
||||
|
||||
if (result.Succeeded)
|
||||
if (user is not null)
|
||||
{
|
||||
// Add the display_name claim to the cookie so the layout can show
|
||||
// the player's handle without a DB hit on every request.
|
||||
var user = await userManager.FindByEmailAsync(Input.Email);
|
||||
if (user is not null)
|
||||
var result = await signInManager.PasswordSignInAsync(
|
||||
user,
|
||||
Input.Password,
|
||||
Input.RememberMe,
|
||||
lockoutOnFailure: true);
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
// Embed display_name in the cookie so the nav bar shows the
|
||||
// player's handle without a DB round-trip on every request.
|
||||
var extraClaims = new[]
|
||||
{
|
||||
new Claim("display_name", user.DisplayName ?? user.Email ?? string.Empty),
|
||||
};
|
||||
await signInManager.SignInWithClaimsAsync(user, Input.RememberMe, extraClaims);
|
||||
return SafeRedirect(ReturnUrl);
|
||||
}
|
||||
|
||||
return SafeRedirect(ReturnUrl);
|
||||
if (result.IsLockedOut)
|
||||
{
|
||||
ErrorMessage = "Too many failed attempts. Please try again later.";
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.IsLockedOut)
|
||||
{
|
||||
// Generic message — does not reveal whether the email exists.
|
||||
ErrorMessage = "Too many failed attempts. Please try again later.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
// Generic: do not confirm whether the email is registered (prevents enumeration).
|
||||
ErrorMessage = "Invalid email or password.";
|
||||
// Generic: does not confirm whether the identifier exists (prevents enumeration).
|
||||
ErrorMessage = "Invalid username/email or password.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@page
|
||||
@page "/how-to-play"
|
||||
@model HowToPlayModel
|
||||
@{
|
||||
ViewData["Title"] = "How To Play";
|
||||
|
||||
@@ -8,6 +8,15 @@
|
||||
}
|
||||
|
||||
<section class="hero">
|
||||
@if (!string.IsNullOrEmpty(Model.CdnBaseUrl))
|
||||
{
|
||||
@* Hero background sourced from CDN. Upload hero-bg.jpg to /website/ on the CDN to activate. *@
|
||||
<img src="@(Model.CdnBaseUrl)/website/hero-bg.jpg"
|
||||
alt=""
|
||||
class="hero-bg-img"
|
||||
aria-hidden="true"
|
||||
loading="eager">
|
||||
}
|
||||
<div class="hero-content">
|
||||
<h1 class="hero-title">Aeternalis</h1>
|
||||
<p class="hero-tagline">Channel the Archspirits. Shape the mindscape. Fill the void with stars.</p>
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
namespace SOR.Website.Pages;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
public sealed class IndexModel : PageModel
|
||||
public sealed class IndexModel(IConfiguration config) : PageModel
|
||||
{
|
||||
public void OnGet() { }
|
||||
/// <summary>
|
||||
/// CDN base URL for sourcing website art (hero image, etc.).
|
||||
/// e.g. https://cdn.aeternalisgames.com
|
||||
/// </summary>
|
||||
public string CdnBaseUrl { get; private set; } = string.Empty;
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
CdnBaseUrl = config["Cdn:PublicBaseUrl"]?.TrimEnd('/') ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Channeler</th>
|
||||
<th scope="col">Rank Score</th>
|
||||
<th scope="col">Games Played</th>
|
||||
<th scope="col">Games Won</th>
|
||||
<th scope="col">Win Rate</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -42,7 +45,6 @@
|
||||
<td class="rank-cell">
|
||||
@if (rank <= 3)
|
||||
{
|
||||
@* Rank icons use plain text fallbacks — no image dependency *@
|
||||
<span class="rank-badge rank-badge-@rank" aria-label="Rank @rank">@rank</span>
|
||||
}
|
||||
else
|
||||
@@ -50,12 +52,14 @@
|
||||
@rank
|
||||
}
|
||||
</td>
|
||||
@* DisplayName auto-encoded by Razor *@
|
||||
<td class="name-cell">
|
||||
@entry.DisplayName
|
||||
@if (isSelf) { <span class="self-tag" aria-label="You">(you)</span> }
|
||||
</td>
|
||||
<td class="score-cell">@entry.RankScore</td>
|
||||
<td class="stat-cell">@entry.GamesPlayed</td>
|
||||
<td class="stat-cell">@entry.GamesWon</td>
|
||||
<td class="stat-cell">@entry.WinRateDisplay</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
@@ -3,17 +3,20 @@ namespace SOR.Website.Pages;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Identity;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Public leaderboard showing top ranked players.
|
||||
/// Public leaderboard showing top ranked players with win/loss stats.
|
||||
///
|
||||
/// Security controls:
|
||||
/// - Only exposes: DisplayName, RankScore. Never: Email, AccountId, or internal fields.
|
||||
/// - Only exposes: DisplayName, RankScore, GamesPlayed, GamesWon.
|
||||
/// Never: Email, AccountId, or internal fields.
|
||||
/// - AI accounts and accounts hidden from leaderboard are excluded at query level.
|
||||
/// - Pagination limits response size.
|
||||
/// </summary>
|
||||
public sealed class LeaderboardModel(SorIdentityDbContext identity) : PageModel
|
||||
public sealed class LeaderboardModel(
|
||||
SorIdentityDbContext identity,
|
||||
GameDbContext game) : PageModel
|
||||
{
|
||||
public const int PageSize = 50;
|
||||
|
||||
@@ -22,31 +25,88 @@ public sealed class LeaderboardModel(SorIdentityDbContext identity) : PageModel
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
// Only safe-to-display fields are projected — email and internal IDs are excluded.
|
||||
Entries = await identity.Users
|
||||
// Step 1 — pull the top-ranked accounts (identity schema).
|
||||
var accounts = await identity.Users
|
||||
.Where(a => !a.IsAi && !a.IsHiddenFromLeaderboard)
|
||||
.OrderByDescending(a => a.RankScore)
|
||||
.Take(PageSize)
|
||||
.Select(a => new LeaderboardEntry
|
||||
.Select(a => new { a.Id, a.DisplayName, a.RankScore })
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
if (accounts.Count == 0)
|
||||
{
|
||||
Entries = [];
|
||||
return;
|
||||
}
|
||||
|
||||
var accountIds = accounts.Select(a => a.Id).ToHashSet();
|
||||
|
||||
// Step 2 — pull completed game sessions for those accounts (game schema).
|
||||
// A session counts for a player if they appear in any seat.
|
||||
// WinnerAccountId being in the set means they won that session.
|
||||
var sessions = await game.GameSessions
|
||||
.Where(s => s.Status == GameSessionStatus.Completed
|
||||
&& (accountIds.Contains(s.PlayerOneAccountId)
|
||||
|| accountIds.Contains(s.PlayerTwoAccountId)))
|
||||
.Select(s => new
|
||||
{
|
||||
DisplayName = a.DisplayName ?? "Channeler",
|
||||
RankScore = a.RankScore,
|
||||
s.PlayerOneAccountId,
|
||||
s.PlayerTwoAccountId,
|
||||
s.WinnerAccountId,
|
||||
})
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Current user's display name (to highlight their entry)
|
||||
// Step 3 — aggregate wins and plays per account in memory.
|
||||
var plays = new Dictionary<Guid, int>();
|
||||
var wins = new Dictionary<Guid, int>();
|
||||
|
||||
foreach (var s in sessions)
|
||||
{
|
||||
foreach (var id in new[] { s.PlayerOneAccountId, s.PlayerTwoAccountId }
|
||||
.Where(accountIds.Contains))
|
||||
{
|
||||
plays.TryGetValue(id, out var p);
|
||||
plays[id] = p + 1;
|
||||
|
||||
if (s.WinnerAccountId == id)
|
||||
{
|
||||
wins.TryGetValue(id, out var w);
|
||||
wins[id] = w + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Entries = accounts
|
||||
.Select(a =>
|
||||
{
|
||||
var played = plays.GetValueOrDefault(a.Id);
|
||||
var won = wins.GetValueOrDefault(a.Id);
|
||||
return new LeaderboardEntry
|
||||
{
|
||||
DisplayName = a.DisplayName ?? "Channeler",
|
||||
RankScore = a.RankScore,
|
||||
GamesPlayed = played,
|
||||
GamesWon = won,
|
||||
WinRate = played > 0 ? (double)won / played : 0,
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (User.Identity?.IsAuthenticated == true)
|
||||
CurrentUserDisplayName = User.FindFirst("display_name")?.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Public-safe projection: only display name and rank score.
|
||||
/// Email, AccountId, and moderation state are intentionally excluded.
|
||||
/// </summary>
|
||||
public sealed class LeaderboardEntry
|
||||
{
|
||||
public string DisplayName { get; init; } = string.Empty;
|
||||
public int RankScore { get; init; }
|
||||
public int RankScore { get; init; }
|
||||
public int GamesPlayed { get; init; }
|
||||
public int GamesWon { get; init; }
|
||||
public double WinRate { get; init; }
|
||||
|
||||
public string WinRateDisplay =>
|
||||
GamesPlayed == 0 ? "—" : $"{WinRate:P0}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "News";
|
||||
ViewData["MetaDescription"] = "Patch notes, set releases, and announcements from Aeternalis Games.";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
@@ -12,8 +13,46 @@
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="coming-soon-block">
|
||||
<p>News and patch notes are coming soon. Check back after launch.</p>
|
||||
<a href="/" class="btn btn-ghost">Back to Home</a>
|
||||
</div>
|
||||
@if (!Model.Posts.Any())
|
||||
{
|
||||
<div class="coming-soon-block">
|
||||
<p>No announcements yet. Check back after launch.</p>
|
||||
<a href="/" class="btn btn-ghost">Back to Home</a>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="news-list">
|
||||
@foreach (var post in Model.Posts)
|
||||
{
|
||||
<article class="news-card">
|
||||
@if (post.HeroImageUrl is not null)
|
||||
{
|
||||
<a href="/news/@post.Slug" class="news-card-img-link">
|
||||
<img src="@post.HeroImageUrl"
|
||||
alt="@post.Title"
|
||||
class="news-card-img"
|
||||
loading="lazy">
|
||||
</a>
|
||||
}
|
||||
<div class="news-card-body">
|
||||
<div class="news-card-meta">
|
||||
<time datetime="@post.PublishedAt!.Value.ToString("yyyy-MM-dd")">
|
||||
@post.PublishedAt!.Value.ToString("MMMM d, yyyy")
|
||||
</time>
|
||||
<span class="news-author">@post.AuthorName</span>
|
||||
</div>
|
||||
<h2 class="news-card-title">
|
||||
<a href="/news/@post.Slug">@post.Title</a>
|
||||
</h2>
|
||||
@if (!string.IsNullOrWhiteSpace(post.Summary))
|
||||
{
|
||||
<p class="news-card-summary">@post.Summary</p>
|
||||
}
|
||||
<a href="/news/@post.Slug" class="news-read-more">Read more →</a>
|
||||
</div>
|
||||
</article>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
namespace SOR.Website.Pages.News;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Catalog;
|
||||
|
||||
public sealed class IndexModel : PageModel
|
||||
public sealed class IndexModel(CatalogDbContext catalog) : PageModel
|
||||
{
|
||||
public void OnGet() { }
|
||||
public IReadOnlyList<NewsPost> Posts { get; private set; } = [];
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Posts = await catalog.NewsPosts
|
||||
.Where(p => p.IsPublished && p.PublishedAt <= DateTimeOffset.UtcNow)
|
||||
.OrderByDescending(p => p.PublishedAt)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
@page "/news/{slug}"
|
||||
@model PostModel
|
||||
@{
|
||||
ViewData["Title"] = Model.Post?.Title ?? "Post Not Found";
|
||||
if (Model.Post is not null)
|
||||
{
|
||||
ViewData["MetaDescription"] = Model.Post.Summary;
|
||||
ViewData["OgTitle"] = Model.Post.Title;
|
||||
ViewData["OgDescription"] = Model.Post.Summary;
|
||||
if (Model.Post.HeroImageUrl is not null)
|
||||
ViewData["OgImage"] = Model.Post.HeroImageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@if (Model.Post is null)
|
||||
{
|
||||
<div class="container prose-page">
|
||||
<div class="empty-state">
|
||||
<p>Post not found.</p>
|
||||
<a href="/news" class="btn btn-ghost">Back to News</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<article class="news-post">
|
||||
@if (Model.Post.HeroImageUrl is not null)
|
||||
{
|
||||
<div class="news-post-hero">
|
||||
<img src="@Model.Post.HeroImageUrl"
|
||||
alt="@Model.Post.Title"
|
||||
class="news-post-hero-img">
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="container news-post-content">
|
||||
<header class="news-post-header">
|
||||
<div class="news-card-meta">
|
||||
<time datetime="@Model.Post.PublishedAt!.Value.ToString("yyyy-MM-dd")">
|
||||
@Model.Post.PublishedAt!.Value.ToString("MMMM d, yyyy")
|
||||
</time>
|
||||
<span class="news-author">@Model.Post.AuthorName</span>
|
||||
</div>
|
||||
<h1>@Model.Post.Title</h1>
|
||||
@if (!string.IsNullOrWhiteSpace(Model.Post.Summary))
|
||||
{
|
||||
<p class="news-post-summary">@Model.Post.Summary</p>
|
||||
}
|
||||
</header>
|
||||
|
||||
@* BodyHtml is admin-authored HTML — rendered raw intentionally.
|
||||
Only admin-role users can write posts, so this is safe. *@
|
||||
<div class="news-post-body prose">
|
||||
@Html.Raw(Model.Post.BodyHtml)
|
||||
</div>
|
||||
|
||||
<footer class="news-post-footer">
|
||||
<a href="/news" class="btn btn-ghost">← All News</a>
|
||||
</footer>
|
||||
</div>
|
||||
</article>
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace SOR.Website.Pages.News;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Catalog;
|
||||
|
||||
public sealed class PostModel(CatalogDbContext catalog) : PageModel
|
||||
{
|
||||
public NewsPost? Post { get; private set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string slug)
|
||||
{
|
||||
Post = await catalog.NewsPosts
|
||||
.Where(p => p.Slug == slug
|
||||
&& p.IsPublished
|
||||
&& p.PublishedAt <= DateTimeOffset.UtcNow)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
// 404 for unknown or unpublished slugs — don't leak existence of drafts.
|
||||
if (Post is null)
|
||||
return NotFound();
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,8 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
/// </summary>
|
||||
public sealed class WebclientModel : PageModel
|
||||
{
|
||||
// The actual webclient URL is configured separately and may live on a subdomain.
|
||||
// For Phase 1 this is a placeholder. Replace with the real client URL when deployed.
|
||||
public const string ClientUrl = "/webclient/app";
|
||||
// Hosted on its own subdomain so the game client can be updated independently.
|
||||
public const string ClientUrl = "https://webclient.aeternalisgames.com";
|
||||
|
||||
public bool IsAuthenticated => User.Identity?.IsAuthenticated == true;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ builder.Services.AddDataProtection()
|
||||
// ── Identity databases ────────────────────────────────────────────────────────
|
||||
builder.Services.AddIdentityDatabase(builder.Configuration);
|
||||
builder.Services.AddCatalogDatabase(builder.Configuration);
|
||||
builder.Services.AddGameDatabase(builder.Configuration);
|
||||
|
||||
// ── ASP.NET Core Identity ─────────────────────────────────────────────────────
|
||||
// Registers UserManager<Account>, SignInManager<Account>, and all token providers.
|
||||
|
||||
Reference in New Issue
Block a user