checkpoint

This commit is contained in:
2026-10-28 13:23:35 +02:00
parent cce5e348b3
commit 33dad8ca5a
26 changed files with 1949 additions and 49 deletions
+42 -15
View File
@@ -1,21 +1,48 @@
@page
@model StatiKosev.Pages.Gallery
@{
Layout = null;
ViewData["Title"] = StringValues["Gallery"];
}
@section Head {
<link rel="stylesheet" href="~/styles/gallery.css" asp-append-version="true"/>
}
<!DOCTYPE html>
<section class="slideshow" aria-roledescription="carousel" aria-label="@StringValues["Gallery"]">
<h1>@StringValues["Gallery"]</h1>
<html>
<head>
<title>
@StringValues["Gallery"]
</title>
</head>
<body>
<div>
</div>
</body>
</html>
@if (Model.Images.Count == 0)
{
<p>@StringValues["GalleryEmpty"]</p>
}
else
{
@* without JavaScript this is a swipeable scroll-snap strip; slideshow.js adds the buttons and autoplay *@
<div class="slides" tabindex="0">
@for (var i = 0; i < Model.Images.Count; i++)
{
<figure class="slide" role="group" aria-roledescription="slide"
aria-label="@StringValues["SlideOf", i + 1, Model.Images.Count]">
<img src="@Model.Images[i]" alt="@StringValues["GoToSlide", i + 1]" asp-append-version="true"
loading="@(i == 0 ? "eager" : "lazy")"/>
</figure>
}
</div>
<div class="slideshow-controls" hidden>
<button type="button" class="slide-prev" aria-label="@StringValues["Previous"]">&#8249;</button>
<div class="slide-dots">
@for (var i = 0; i < Model.Images.Count; i++)
{
<button type="button" data-index="@i" aria-label="@StringValues["GoToSlide", i + 1]"></button>
}
</div>
<button type="button" class="slide-toggle" data-pause="@StringValues["Pause"]" data-play="@StringValues["Play"]"
aria-label="@StringValues["Pause"]">&#10074;&#10074;</button>
<button type="button" class="slide-next" aria-label="@StringValues["Next"]">&#8250;</button>
</div>
}
</section>
@section Scripts {
<script src="~/scripts/slideshow.js" asp-append-version="true"></script>
}
+17 -3
View File
@@ -2,10 +2,24 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
namespace StatiKosev.Pages;
public class Gallery : PageModel
public class Gallery(IWebHostEnvironment env) : PageModel
{
static readonly string[] ImageExtensions = [".png", ".jpg", ".jpeg", ".webp", ".gif"];
public IReadOnlyList<string> Images { get; private set; } = [];
//every image in wwwroot/images except the profile photo used on the home page
public void OnGet()
{
var dir = Path.Combine(env.WebRootPath, "images");
if (!Directory.Exists(dir)) return;
Images = Directory.EnumerateFiles(dir)
.Where(f => ImageExtensions.Contains(Path.GetExtension(f).ToLowerInvariant()))
.Select(Path.GetFileName)
.Where(n => !n!.StartsWith("profile.", StringComparison.OrdinalIgnoreCase))
.Order()
.Select(n => "/images/" + n)
.ToList();
}
}
}
+30
View File
@@ -0,0 +1,30 @@
@page
@model StatiKosev.Pages.InboxModel
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Antiforgery
@{
ViewData["Title"] = StringValues["Messages"];
}
@section Head {
<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">
<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>
@section Scripts {
<script src="~/scripts/inbox.js" asp-append-version="true"></script>
}
+12
View File
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace StatiKosev.Pages;
[Authorize(Policy = "AdminOnly")]
public class InboxModel : PageModel
{
public void OnGet()
{
}
}
+36
View File
@@ -0,0 +1,36 @@
@page
@model StatiKosev.Pages.LoginModel
@{
ViewData["Title"] = StringValues["Login"];
}
@section Head {
<link rel="stylesheet" href="~/styles/account.css" asp-append-version="true"/>
}
<div class="auth-forms">
<form method="post" action="/account/login" asp-antiforgery="true" class="auth-card" data-once>
<h1>@StringValues["Login"]</h1>
<input type="hidden" name="returnUrl" value="@Model.ReturnUrl"/>
<label>@StringValues["Email"]
<input type="email" name="email" required autocomplete="username"/>
</label>
<label>@StringValues["Password"]
<input type="password" name="password" required autocomplete="current-password"/>
</label>
<button type="submit">@StringValues["Login"]</button>
</form>
<form method="post" action="/account/register" asp-antiforgery="true" class="auth-card" data-once>
<h1>@StringValues["Register"]</h1>
<input type="hidden" name="returnUrl" value="@Model.ReturnUrl"/>
<label>@StringValues["Email"]
<input type="email" name="email" required autocomplete="email"/>
</label>
<label>@StringValues["Password"]
<input type="password" name="password" required minlength="8" autocomplete="new-password"
aria-describedby="password-hint"/>
</label>
<p id="password-hint" class="hint">@StringValues["PasswordHint"]</p>
<button type="submit">@StringValues["Register"]</button>
</form>
</div>
+15
View File
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace StatiKosev.Pages;
public class LoginModel : PageModel
{
[BindProperty(SupportsGet = true)]
public string? ReturnUrl { get; set; }
public void OnGet()
{
if (!Url.IsLocalUrl(ReturnUrl)) ReturnUrl = "/";
}
}
+41 -5
View File
@@ -1,8 +1,19 @@
@{
var path = Context.Request.Path.Value ?? "/";
var lang = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
var loggedIn = User.Identity?.IsAuthenticated == true;
string Active(string p) => path.Equals(p, StringComparison.OrdinalIgnoreCase) ? "active" : "";
string? Current(string p) => Active(p) == "" ? null : "page";
//one-line notice: message status from the controller (TempData), rate limit (?wait=1), login/register errors (?auth=)
var status = TempData["Status"] as string;
var statusType = TempData["StatusType"] as string ?? "info";
if (Context.Request.Query["wait"] == "1")
(status, statusType) = (StringValues["TooManyMessages"].Value, "error");
else if (Context.Request.Query["auth"] == "login-failed")
(status, statusType) = (StringValues["LoginFailed"].Value, "error");
else if (Context.Request.Query["auth"] == "register-failed")
(status, statusType) = (StringValues["RegisterFailed"].Value, "error");
}
<!DOCTYPE html>
@@ -11,23 +22,48 @@
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>@StringValues["Title"]</title>
<title>@(ViewData["Title"] ?? StringValues["Title"])</title>
<link rel="stylesheet" href="~/styles/site.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/styles/message-form.css" asp-append-version="true"/>
@await RenderSectionAsync("Head", required: false)
</head>
<body>
<header class="site-header">
<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>
<a asp-page="/Contact" class="@Active("/Contact")" aria-current="@Current("/Contact")">@StringValues["Contact"]</a>
@if (User.IsInRole("Admin"))
{
<a asp-page="/Inbox" class="@Active("/Inbox")" aria-current="@Current("/Inbox")">@StringValues["Messages"]</a>
}
</nav>
<div class="lang-switch">
<a href="/set-language?culture=bg&returnUrl=@Context.Request.Path" class="@(lang == "bg" ? "active" : "")" lang="bg">Български</a>
<a href="/set-language?culture=en&returnUrl=@Context.Request.Path" class="@(lang == "en" ? "active" : "")" lang="en">English</a>
<div class="header-end">
@if (loggedIn)
{
<form method="post" action="/account/logout" asp-antiforgery="true" class="logout-form">
<span class="user-name">@User.Identity!.Name</span>
<button type="submit">@StringValues["Logout"]</button>
</form>
}
else
{
<a asp-page="/Login" asp-route-returnUrl="@(Active("/Login") == "" ? path : null)" class="@Active("/Login")" aria-current="@Current("/Login")">@StringValues["Login"]</a>
}
<div class="lang-switch">
<a href="/set-language?culture=bg&returnUrl=@Context.Request.Path" class="@(lang == "bg" ? "active" : "")" lang="bg">Български</a>
<a href="/set-language?culture=en&returnUrl=@Context.Request.Path" class="@(lang == "en" ? "active" : "")" lang="en">English</a>
</div>
</div>
</header>
@if (status is not null)
{
<p class="flash flash-@statusType" role="status">@status</p>
}
<main>@RenderBody()</main>
<script src="~/scripts/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>