mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 23:48:45 -07:00
11377b46d5
Port the December signup-code feature to the 2020.03 branch. While account creation is disabled, the only way in is now an admin-issued single-use signup code, redeemed on the public site's /join page. Because the 2020.03 watch login is device-id-bound with no code field, a new device refused at the signups-disabled gate (PlatformLogin / account create) is stashed in a PendingDevices table keyed by the real client IP (CF-Connecting-IP aware). The /join page shows the player the device their own client just reported; they enter code + username and the account is minted bound to that device, so the next launch logs straight in. No watch changes. - SignupCodeEntity + PendingDeviceEntity; tables created via idempotent CREATE TABLE IF NOT EXISTS at boot (Program.cs Postgres patch block + SQLite path) since they post-date the migration chain. - SignupCodeService: generate / list / revoke / redeem + pending-device capture (single-use, expiry, revoke validation). - Admin: GET/POST signup-codes + revoke endpoints and a Signup codes admin-ui page (generate with descriptor/expiry, status table, revoke). - Public: anonymous /api/site/v1/join pending-devices + redeem, and a /join site page (+ header link). - README documents the flow.
105 lines
3.4 KiB
TypeScript
105 lines
3.4 KiB
TypeScript
import { NavLink, Link, useLocation, useNavigate } from 'react-router-dom';
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
|
const NAV = [
|
|
{ to: '/', label: 'Home', exact: true },
|
|
{ to: '/feed', label: 'Feed' },
|
|
{ to: '/players', label: 'Players' },
|
|
{ to: '/rooms', label: 'Rooms' },
|
|
{ to: '/join', label: 'Join' },
|
|
];
|
|
|
|
export function Header() {
|
|
const [open, setOpen] = useState(false);
|
|
const [q, setQ] = useState('');
|
|
const nav = useNavigate();
|
|
const loc = useLocation();
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
|
// Close the mobile drawer on route change so tapping a nav item
|
|
// doesn't leave a half-open overlay covering the page.
|
|
useEffect(() => { setOpen(false); }, [loc.pathname]);
|
|
|
|
const submitSearch = (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
const v = q.trim();
|
|
if (v) nav(`/players?q=${encodeURIComponent(v)}`);
|
|
};
|
|
|
|
return (
|
|
<header className="sticky top-0 z-40 border-b border-ink-800 bg-ink-950/85 backdrop-blur">
|
|
<div className="mx-auto max-w-6xl flex items-center gap-4 px-4 sm:px-6 py-3">
|
|
<Link to="/" className="flex items-center gap-2 shrink-0">
|
|
<span className="inline-block size-6 rounded-md bg-gradient-to-br from-brand-400 to-brand-700 shadow-inner" />
|
|
<span className="font-semibold text-ink-50 tracking-tight">DorkNet</span>
|
|
</Link>
|
|
|
|
<nav className="hidden md:flex items-center gap-1 ml-2">
|
|
{NAV.map(n => (
|
|
<NavLink
|
|
key={n.to}
|
|
to={n.to}
|
|
end={n.exact}
|
|
className={({ isActive }) =>
|
|
`px-3 py-1.5 rounded-md text-sm transition-colors ${
|
|
isActive ? 'bg-ink-800 text-ink-50' : 'text-ink-300 hover:bg-ink-800/60 hover:text-ink-100'
|
|
}`
|
|
}
|
|
>
|
|
{n.label}
|
|
</NavLink>
|
|
))}
|
|
</nav>
|
|
|
|
<form onSubmit={submitSearch} className="ml-auto hidden sm:flex flex-1 max-w-xs">
|
|
<input
|
|
ref={inputRef}
|
|
value={q}
|
|
onChange={e => setQ(e.target.value)}
|
|
placeholder="Search players…"
|
|
className="input"
|
|
/>
|
|
</form>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={() => setOpen(o => !o)}
|
|
aria-label="Toggle menu"
|
|
className="md:hidden btn-ghost text-sm ml-auto"
|
|
>
|
|
{open ? 'Close' : 'Menu'}
|
|
</button>
|
|
</div>
|
|
|
|
{open && (
|
|
<div className="md:hidden border-t border-ink-800 bg-ink-900">
|
|
<div className="mx-auto max-w-6xl px-4 sm:px-6 py-3 flex flex-col gap-2">
|
|
<form onSubmit={submitSearch} className="flex">
|
|
<input
|
|
value={q}
|
|
onChange={e => setQ(e.target.value)}
|
|
placeholder="Search players…"
|
|
className="input"
|
|
/>
|
|
</form>
|
|
<nav className="flex flex-col gap-1">
|
|
{NAV.map(n => (
|
|
<NavLink
|
|
key={n.to}
|
|
to={n.to}
|
|
end={n.exact}
|
|
className={({ isActive }) =>
|
|
`px-3 py-2 rounded-md text-sm ${isActive ? 'bg-ink-800 text-ink-50' : 'text-ink-200 hover:bg-ink-800/60'}`
|
|
}
|
|
>
|
|
{n.label}
|
|
</NavLink>
|
|
))}
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</header>
|
|
);
|
|
}
|