Gitea Actions Runner Test / test-job (push) Successful in 2s
CI / check (push) Successful in 30s
CI / tests-integration (push) Successful in 1m42s
CI / tests-unit (push) Failing after 1m49s
CI / tests-ui (push) Successful in 2m31s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
Second review pass covering security, performance, admin tooling and the public/room flows. All HIGH and MEDIUM findings from the audit are resolved; nothing in this commit changes the visible feature set. Authentication & session security - CSP is now set on the request headers in the proxy, which is what Next.js uses to derive the render nonce, so the nonce is effective. - 2FA: an already-enabled user cannot re-enroll, the setup endpoint is rate-limited per account, and confirmed codes are persisted so the second secret no longer silently never applies. - Password reset revokes the ticket, authTicket and all personal access tokens, and bumps the token version so existing sessions die. The same revocation is now wired into the staff-side password reset. - /reset and /verify return a stable error code instead of raw text; the mail lookups are ordered by id so duplicates cannot vary between runs. - Resending the verification mail gets a per-address cooldown on top of the per-user limit. - Issue API tokens with the narrower radio/ticket ability set instead of "*". Authorization & input handling - Mid-rank staff can no longer keep dynamically granted non-view admin.* permissions: existing grants are revoked by migration and the grant lookup is restricted to "%.view". Rank guards use the dynamic super-admin check. - Alerting a user is permission-checked and audited like the other tools. - Material mutations (giveCredits/giveDuckets/giveDiamonds, the admin user actions route, bulk user actions) are capped and rank-guarded, and bulk ids are bounded. - updateRoom / updateRoomItem write through a field allowlist, and items may only be edited through their own room. - Classnames reaching the filesystem are validated before use so a crafted value cannot escape the asset directories. - The word filter now also covers offline mails, guild forum threads and replies, and user mottos. - Media uploads are validated by magic bytes, /api/media requires the page edit permission, APP_URL must be configured once mail is enabled, and the diagnostics error route checks the fetch site header. Admin tooling - Secret settings render masked and cannot be overwritten with a blank or an arbitrary raw key; radio credentials are new password inputs. - Commandocentrum balance changes are audited. - Admin list pagination reads the caller's per-page instead of the max, and the log exporter caps offset and search length. Performance - Catalog translations are cached per module, with a cheap revision hash; the public online count uses a stale window instead of hammering the DB. - The cache warmup now primes the payload the home route actually reads. - TopHeader batches its queries into one round trip, and LCP avatars load eagerly. - motion/react and sonner are no longer part of the root layout; the nav dropdown and mobile nav panels are lazy client chunks. Anonymous visitors again get the navigation chrome, and public pages get an edge cacheable response. Accessibility - Nested <main> elements in phase pages became <section>; the page entrance and route progress animations are pure CSS that respect reduced motion.
223 lines
6.5 KiB
TypeScript
223 lines
6.5 KiB
TypeScript
import { desc, eq } from "drizzle-orm";
|
|
import type { Metadata } from "next";
|
|
import { headers } from "next/headers";
|
|
import Image from "next/image";
|
|
import { redirect } from "next/navigation";
|
|
import { getTranslations } from "next-intl/server";
|
|
import {
|
|
AuthPageFrame,
|
|
AuthUsersCards,
|
|
} from "@/components/auth/auth-page-frame";
|
|
import { LoginForm } from "@/components/auth/login-form";
|
|
import { SurfaceCard } from "@/components/surface-card";
|
|
import { auth } from "@/lib/auth";
|
|
import { safeRedirectPath } from "@/lib/auth/safe-redirect";
|
|
import { cached } from "@/lib/cache";
|
|
|
|
import { db, User } from "@/lib/db";
|
|
import { resolveHotelName } from "@/lib/hotel-name";
|
|
import { captchaConfig } from "@/lib/services/captcha";
|
|
import { cachedOnlineCount } from "@/lib/services/public-counters";
|
|
import { siteSettings } from "@/lib/services/site-settings";
|
|
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
const t = await getTranslations("pages.login");
|
|
const title = t("title");
|
|
const description = t("subtitle");
|
|
return {
|
|
title,
|
|
description,
|
|
// Sign-in is a dead end for crawlers and duplicates the homepage copy.
|
|
robots: { index: false, follow: false },
|
|
openGraph: { title, description, type: "website" },
|
|
};
|
|
}
|
|
|
|
export default async function LoginPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{
|
|
from?: string;
|
|
registered?: string;
|
|
reset?: string;
|
|
}>;
|
|
}) {
|
|
const t = await getTranslations("pages.login");
|
|
const [hotelName, cfg, logo] = await Promise.all([
|
|
resolveHotelName(),
|
|
captchaConfig(),
|
|
siteSettings.get("cms_logo", ""),
|
|
]);
|
|
const nonce = (await headers()).get("x-nonce") ?? undefined;
|
|
|
|
const sp = await searchParams;
|
|
const redirectTo = safeRedirectPath(sp.from);
|
|
|
|
// Already signed in: the form has nothing to do here. Honour `from` first so
|
|
// an admin bounced off /admin lands back where they were heading.
|
|
const session = await auth();
|
|
if (session?.user?.id) redirect(redirectTo);
|
|
|
|
const [online, recentUsers, latestUsers] = await Promise.all([
|
|
cachedOnlineCount().catch(() => 0),
|
|
cached(
|
|
"auth_online_users",
|
|
10_000,
|
|
() =>
|
|
db
|
|
.select({ id: User.id, username: User.username, look: User.look })
|
|
.from(User)
|
|
.where(eq(User.online, "1"))
|
|
.limit(8),
|
|
{ staleMs: 30000 },
|
|
).catch(() => []),
|
|
cached(
|
|
"auth_latest_users",
|
|
30_000,
|
|
() =>
|
|
db
|
|
.select({ id: User.id, username: User.username, look: User.look })
|
|
.from(User)
|
|
.orderBy(desc(User.accountCreated))
|
|
.limit(8),
|
|
{ staleMs: 60000 },
|
|
).catch(() => []),
|
|
]);
|
|
|
|
// `/login?registered=1` is where the sign-up form lands when it could not
|
|
// auto sign-in (e-mail verification still pending). Without this notice the
|
|
// visitor would only see an empty login form and no sign their account
|
|
// exists.
|
|
const notice =
|
|
sp.registered === "1" ? (
|
|
<p
|
|
role="status"
|
|
className="auth-alert auth-alert--success animate-fade-in-up m-0 mb-4"
|
|
>
|
|
{t("registeredSuccess")}
|
|
</p>
|
|
) : sp.reset === "1" ? (
|
|
// `?reset=1` comes from a successful password reset; saying so matters
|
|
// because the visitor just changed their password and a silent form
|
|
// reads like the reset failed.
|
|
<p
|
|
role="status"
|
|
className="auth-alert auth-alert--success animate-fade-in-up m-0 mb-4"
|
|
>
|
|
{t("passwordChanged")}
|
|
</p>
|
|
) : undefined;
|
|
|
|
return (
|
|
<AuthPageFrame
|
|
hotelName={hotelName}
|
|
logo={logo}
|
|
title={t("title")}
|
|
subtitle={t("subtitle")}
|
|
notice={notice}
|
|
form={
|
|
<LoginForm
|
|
redirectTo={redirectTo}
|
|
captcha={{
|
|
provider: cfg.provider,
|
|
siteKey: cfg.siteKey || undefined,
|
|
field: cfg.field || undefined,
|
|
}}
|
|
nonce={nonce}
|
|
/>
|
|
}
|
|
>
|
|
<SurfaceCard
|
|
className="card-glow relative overflow-hidden p-6 text-center"
|
|
style={{
|
|
borderColor:
|
|
"color-mix(in srgb, var(--color-primary) 20%, transparent)",
|
|
}}
|
|
>
|
|
<div
|
|
className="absolute inset-0"
|
|
style={{
|
|
background:
|
|
"linear-gradient(135deg, color-mix(in srgb, var(--color-primary) 10%, transparent), color-mix(in srgb, var(--color-accent) 10%, transparent))",
|
|
}}
|
|
/>
|
|
<div aria-hidden="true" className="absolute inset-0 overflow-hidden">
|
|
<div className="brand-halo left-1/2 top-0 h-64 w-[460px] max-w-full -translate-x-1/2 -translate-y-1/2" />
|
|
<div
|
|
className="aurora-blob -left-16 top-10 h-56 w-56"
|
|
style={{
|
|
background:
|
|
"color-mix(in srgb, var(--color-primary) 45%, transparent)",
|
|
}}
|
|
/>
|
|
<div
|
|
className="aurora-blob -right-16 bottom-0 h-56 w-56"
|
|
style={{
|
|
background:
|
|
"color-mix(in srgb, var(--color-accent) 40%, transparent)",
|
|
animationDelay: "-8s",
|
|
}}
|
|
/>
|
|
</div>
|
|
<div className="relative">
|
|
<div className="brand-halo left-1/2 top-8 h-52 w-52 -translate-x-1/2" />
|
|
<Image
|
|
src="/assets/images/FrankwithBag.gif"
|
|
alt="Frank"
|
|
width={130}
|
|
height={170}
|
|
className="relative object-contain mx-auto drop-shadow-xl animate-float"
|
|
unoptimized
|
|
/>
|
|
<div
|
|
className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full text-xs font-bold uppercase tracking-wider mt-4 mb-3 border"
|
|
style={{
|
|
borderColor:
|
|
"color-mix(in srgb, var(--color-primary) 30%, transparent)",
|
|
background:
|
|
"color-mix(in srgb, var(--color-surface) 72%, transparent)",
|
|
color: "var(--color-primary-readable, var(--color-primary))",
|
|
boxShadow:
|
|
"0 8px 20px -12px color-mix(in srgb, var(--color-primary) 70%, transparent)",
|
|
}}
|
|
>
|
|
<span className="relative flex h-2 w-2">
|
|
<span
|
|
className="animate-ping absolute inline-flex h-full w-full rounded-full opacity-75"
|
|
style={{ background: "var(--color-primary)" }}
|
|
/>
|
|
<span
|
|
className="relative inline-flex rounded-full h-2 w-2"
|
|
style={{ background: "var(--color-primary)" }}
|
|
/>
|
|
</span>
|
|
{t("usersOnline", { count: online })}
|
|
</div>
|
|
<h1
|
|
className="text-xl font-black"
|
|
style={{
|
|
color: "var(--color-text-readable)",
|
|
fontFamily: "var(--font-nunito)",
|
|
}}
|
|
>
|
|
{t("welcomeBack")}
|
|
</h1>
|
|
<p
|
|
className="text-xs mt-1.5 mx-auto max-w-[220px] leading-relaxed"
|
|
style={{ color: "var(--color-text-muted)" }}
|
|
>
|
|
{t("welcomeBackSub", { hotelName })}
|
|
</p>
|
|
</div>
|
|
</SurfaceCard>
|
|
|
|
<AuthUsersCards
|
|
recentUsers={recentUsers}
|
|
latestUsers={latestUsers}
|
|
recentTitle={t("whoIsOnline")}
|
|
latestTitle={t("newestCitizens")}
|
|
/>
|
|
</AuthPageFrame>
|
|
);
|
|
}
|