checkpoint

This commit is contained in:
2026-10-28 14:22:27 +02:00
parent 33dad8ca5a
commit bd22fa86b7
11 changed files with 161 additions and 52 deletions
+38 -16
View File
@@ -5,26 +5,48 @@
ViewData["Title"] = StringValues["Messages"];
}
@section Head {
<link rel="stylesheet" href="~/styles/account.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/styles/inbox.css" asp-append-version="true"/>
}
@* messages are loaded as JSON from PrivateMessageController by inbox.js *@
<section class="inbox"
data-api="/messages"
data-token="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken"
data-anonymous="@StringValues["Anonymous"]"
data-mark-read="@StringValues["MarkRead"]"
data-read="@StringValues["Read"]"
data-empty="@StringValues["NoMessages"]"
data-failed="@StringValues["LoadFailed"]">
<header class="inbox-header">
@if (!Model.IsAdmin)
{
@* no account: the admin password is checked by PrivateMessageController.Login *@
<form method="post" asp-controller="PrivateMessage" asp-action="Login" class="auth-card" data-once>
<h1>@StringValues["Messages"]</h1>
<label><input type="checkbox" class="inbox-unread-only"/> @StringValues["UnreadOnly"]</label>
</header>
<p class="inbox-status" role="status" aria-live="polite">@StringValues["Loading"]</p>
<ol class="inbox-list"></ol>
</section>
<label>@StringValues["AdminPassword"]
<input type="password" name="password" required autocomplete="current-password" autofocus/>
</label>
<button type="submit">@StringValues["AdminLogin"]</button>
</form>
}
else
{
@* messages are loaded as JSON from PrivateMessageController by inbox.js *@
<section class="inbox"
data-list="/messages/list"
data-base="/messages"
data-token="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken"
data-anonymous="@StringValues["Anonymous"]"
data-mark-read="@StringValues["MarkRead"]"
data-read="@StringValues["Read"]"
data-empty="@StringValues["NoMessages"]"
data-failed="@StringValues["LoadFailed"]">
<header class="inbox-header">
<h1>@StringValues["Messages"]</h1>
<label><input type="checkbox" class="inbox-unread-only"/> @StringValues["UnreadOnly"]</label>
<form method="post" asp-controller="PrivateMessage" asp-action="Logout" class="inbox-logout">
<button type="submit">@StringValues["AdminLogout"]</button>
</form>
</header>
<p class="inbox-status" role="status" aria-live="polite">@StringValues["Loading"]</p>
<ol class="inbox-list"></ol>
</section>
}
@section Scripts {
<script src="~/scripts/inbox.js" asp-append-version="true"></script>
@if (Model.IsAdmin)
{
<script src="~/scripts/inbox.js" asp-append-version="true"></script>
}
}
+6 -3
View File
@@ -1,12 +1,15 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace StatiKosev.Pages;
[Authorize(Policy = "AdminOnly")]
//open to everyone: shows the admin password form, or the inbox once the admin cookie is set
public class InboxModel : PageModel
{
public void OnGet()
public bool IsAdmin { get; private set; }
public async Task OnGetAsync()
{
IsAdmin = (await HttpContext.AuthenticateAsync(Program.AdminScheme)).Succeeded;
}
}
-4
View File
@@ -32,10 +32,6 @@
<nav class="main-nav" aria-label="@StringValues["Navigation"]">
<a asp-page="/Index" class="@Active("/")" aria-current="@Current("/")">@StringValues["Home"]</a>
<a asp-page="/Gallery" class="@Active("/Gallery")" aria-current="@Current("/Gallery")">@StringValues["Gallery"]</a>
@if (User.IsInRole("Admin"))
{
<a asp-page="/Inbox" class="@Active("/Inbox")" aria-current="@Current("/Inbox")">@StringValues["Messages"]</a>
}
</nav>
<div class="header-end">
@if (loggedIn)