Invitation-only sign-up, invitation e-mails and waitlist
- SIGNUP_MODE=invite (default): a new account needs an open invitation for its address, or the invitation link (then any Google account will do) - admin page "Meghívók": invite many addresses at once, personal message, resend (max 3, 24 h apart), revoke, copy link, mail preview and test copy, waitlist - invitation e-mail in HTML and plain text; Message-ID on the sender's domain, List-Unsubscribe with one-click POST, opt-out list (hashes only) - e-mail texts moved to a shared crate (crates/email-templates) - login page shows the invitation; waitlist for uninvited visitors; unsubscribe page; privacy policy updated - docs/levelkuldes.md: Brevo, DNS (SPF, DKIM, DMARC) and the SMTP setup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -76,6 +76,21 @@ export default async function PrivacyPage() {
|
||||
<td>A megvásárolt szolgáltatás nyújtása, elszámolás</td>
|
||||
<td>Szerződés teljesítése; számviteli kötelezettség (6. cikk (1) c)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Meghívott e-mail-címe, a meghívó neve és személyes üzenete</td>
|
||||
<td>A meghívó elküldése; amíg az oldal zártkörű, csak meghívottak regisztrálhatnak</td>
|
||||
<td>Jogos érdek (6. cikk (1) f)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A várólistán megadott e-mail-cím</td>
|
||||
<td>Értesítés, ha megnyílik az oldal, vagy meghívót küldünk</td>
|
||||
<td>Hozzájárulás (6. cikk (1) a)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Azok a címek, amelyek leiratkoztak a meghívókról (csak a cím egyirányú lenyomata, hash-e)</td>
|
||||
<td>Hogy ezekre a címekre ne küldjünk több meghívót</td>
|
||||
<td>Jogos érdek (6. cikk (1) f)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP-cím, böngésző adatai, a kérések ideje (szervernaplók)</td>
|
||||
<td>Biztonság, hibakeresés, visszaélések kiszűrése</td>
|
||||
@@ -123,6 +138,10 @@ export default async function PrivacyPage() {
|
||||
<li>
|
||||
<strong>Google LLC</strong> – bejelentkezés Google-fiókkal.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Levélküldő szolgáltató</strong> – a rendszerlevelek és a meghívók kézbesítése; a neve az indításkor
|
||||
itt lesz feltüntetve.
|
||||
</li>
|
||||
<li>
|
||||
<strong>OpenRouter, Inc.</strong> és az általa elért modellszolgáltató (jelenleg{" "}
|
||||
<strong>Anthropic PBC</strong>) – az elemzések megírása, kizárólag a 3. pontban leírt csillagászati
|
||||
@@ -142,6 +161,11 @@ export default async function PrivacyPage() {
|
||||
<li>Fiókod adatait, képleteidet és elemzéseidet a fiókod törléséig.</li>
|
||||
<li>A biztonsági mentésekből a törölt adatok legkésőbb 14 nap után tűnnek el.</li>
|
||||
<li>A szervernaplókat legfeljebb 30 napig őrizzük.</li>
|
||||
<li>
|
||||
Az el nem fogadott meghívókat a lejáratuk vagy visszavonásuk után 30 nappal töröljük. A meghívólevelekben
|
||||
bármikor leiratkozhatsz.
|
||||
</li>
|
||||
<li>A várólistán megadott címet a regisztrációdig, vagy amíg nem kéred a törlését.</li>
|
||||
<li>A számlázáshoz szükséges adatokat a számviteli törvény szerinti ideig (8 évig) őrizzük.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
@@ -0,0 +1,472 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { AdminInvitation, InvitationResult, WaitlistEntry } from "@/lib/types";
|
||||
|
||||
const MAX_MESSAGE = 300;
|
||||
|
||||
const STATUS: Record<AdminInvitation["status"], string> = {
|
||||
pending: "Függőben",
|
||||
accepted: "Elfogadva",
|
||||
expired: "Lejárt",
|
||||
revoked: "Visszavonva",
|
||||
};
|
||||
|
||||
const MAIL: Record<AdminInvitation["mail"], string> = {
|
||||
sent: "Elküldve",
|
||||
queued: "Sorban vár",
|
||||
failed: "Sikertelen",
|
||||
archived: "Elküldve (archív)",
|
||||
};
|
||||
|
||||
const RESULT: Record<InvitationResult["status"], string> = {
|
||||
invited: "meghívva",
|
||||
invalid: "érvénytelen cím",
|
||||
already_user: "már felhasználó",
|
||||
already_invited: "már van élő meghívója (újraküldés a listában)",
|
||||
opted_out: "leiratkozott a meghívókról",
|
||||
};
|
||||
|
||||
interface ListData {
|
||||
invitations: AdminInvitation[];
|
||||
waitlist: WaitlistEntry[];
|
||||
signup_mode: "invite" | "open";
|
||||
}
|
||||
|
||||
function CopyLink({ url }: { url: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm btn-ghost"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
setCopied(true);
|
||||
} catch {
|
||||
window.prompt("A meghívólink:", url);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{copied ? "Kimásolva" : "Link másolása"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/** Addresses from free text: one per line, or separated by commas, semicolons or spaces. */
|
||||
function parseEmails(text: string): string[] {
|
||||
return text
|
||||
.split(/[\s,;]+/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
export function AdminInvitations() {
|
||||
const [data, setData] = useState<ListData | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
setData(await api<ListData>("/admin/invitations"));
|
||||
setError(null);
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
return (
|
||||
<div className="field" style={{ gap: 24 }}>
|
||||
{data?.signup_mode === "open" && (
|
||||
<p className="msg" role="status">
|
||||
A regisztráció most nyitott (<code>SIGNUP_MODE=open</code>): bárki beléphet, a meghívó csak értesítés.
|
||||
</p>
|
||||
)}
|
||||
<InviteForm onSent={load} />
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{data && <InvitationList invitations={data.invitations} onChange={load} />}
|
||||
{data && <WaitlistTable waitlist={data.waitlist} onChange={load} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function InviteForm({ onSent }: { onSent: () => Promise<void> }) {
|
||||
const [emails, setEmails] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [locale, setLocale] = useState("hu");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [results, setResults] = useState<InvitationResult[] | null>(null);
|
||||
const count = parseEmails(emails).length;
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setResults(null);
|
||||
try {
|
||||
const res = await api<{ results: InvitationResult[] }>("/admin/invitations", {
|
||||
body: { emails: parseEmails(emails), message: message.trim() || null, locale },
|
||||
});
|
||||
setResults(res.results);
|
||||
if (res.results.some((r) => r.status === "invited")) setEmails("");
|
||||
await onSent();
|
||||
} catch (err) {
|
||||
setError(errorText(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card field" style={{ gap: 16 }} aria-labelledby="invite-title">
|
||||
<h2 id="invite-title" style={{ margin: 0 }}>
|
||||
Új meghívó
|
||||
</h2>
|
||||
<form onSubmit={submit} className="field" style={{ gap: 14 }}>
|
||||
<div className="field">
|
||||
<label htmlFor="invite-emails">E-mail-címek</label>
|
||||
<textarea
|
||||
id="invite-emails"
|
||||
className="inp"
|
||||
rows={3}
|
||||
required
|
||||
value={emails}
|
||||
onChange={(e) => setEmails(e.target.value)}
|
||||
placeholder={"kata@pelda.hu\nbela@pelda.hu"}
|
||||
/>
|
||||
<span className="hint">Soronként egy, vagy vesszővel elválasztva; egyszerre legfeljebb 50.</span>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="invite-message">Személyes üzenet (nem kötelező)</label>
|
||||
<textarea
|
||||
id="invite-message"
|
||||
className="inp"
|
||||
rows={3}
|
||||
maxLength={MAX_MESSAGE}
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
placeholder="Szia! Ezt nézd meg, szerintem tetszeni fog."
|
||||
/>
|
||||
<span className="hint">
|
||||
{message.length}/{MAX_MESSAGE} karakter. Link nem lehet benne (spamszűrők miatt).
|
||||
</span>
|
||||
</div>
|
||||
<div className="row" style={{ gap: 12, alignItems: "flex-end", flexWrap: "wrap" }}>
|
||||
<div className="field" style={{ width: 160 }}>
|
||||
<label htmlFor="invite-locale">A levél nyelve</label>
|
||||
<select id="invite-locale" className="inp" value={locale} onChange={(e) => setLocale(e.target.value)}>
|
||||
<option value="hu">magyar</option>
|
||||
<option value="en">angol</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || count === 0}>
|
||||
{busy ? "Küldés…" : count > 1 ? `${count} meghívó küldése` : "Meghívó küldése"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{results && (
|
||||
<ul className="invite-results" aria-label="Eredmény">
|
||||
{results.map((r) => (
|
||||
<li key={r.email}>
|
||||
<span className={r.status === "invited" ? "msg-ok" : "muted"}>
|
||||
{r.email}: {RESULT[r.status]}
|
||||
</span>
|
||||
{r.url && <CopyLink url={r.url} />}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<MailPreview message={message} locale={locale} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** The invitation e-mail as the recipient sees it, and a test copy to the admin. */
|
||||
function MailPreview({ message, locale }: { message: string; locale: string }) {
|
||||
const [mail, setMail] = useState<{ subject: string; html: string; text: string } | null>(null);
|
||||
const [view, setView] = useState<"html" | "text">("html");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [note, setNote] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
|
||||
async function show(sendToMe: boolean) {
|
||||
setBusy(true);
|
||||
setNote(null);
|
||||
try {
|
||||
const res = await api<{ subject: string; html: string; text: string; sent_to: string | null }>(
|
||||
"/admin/invitations/preview",
|
||||
{ body: { message: message.trim() || null, locale, send_to_me: sendToMe } },
|
||||
);
|
||||
setMail(res);
|
||||
if (res.sent_to) setNote({ ok: true, text: `Tesztlevél a sorban: ${res.sent_to}. A linkjei nem működnek.` });
|
||||
} catch (e) {
|
||||
setNote({ ok: false, text: errorText(e) });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="field mail-preview" style={{ gap: 10 }}>
|
||||
<div className="row" style={{ gap: 8, flexWrap: "wrap" }}>
|
||||
<button type="button" className="btn btn-sm" onClick={() => show(false)} disabled={busy}>
|
||||
{mail ? "Előnézet frissítése" : "Levél előnézete"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => show(true)} disabled={busy}>
|
||||
Teszt küldése magamnak
|
||||
</button>
|
||||
</div>
|
||||
{note && (
|
||||
<p className={note.ok ? "msg msg-ok" : "msg msg-error"} role={note.ok ? "status" : "alert"}>
|
||||
{note.text}
|
||||
</p>
|
||||
)}
|
||||
{mail && (
|
||||
<>
|
||||
<p style={{ margin: 0 }}>
|
||||
<span className="muted">Tárgy:</span> <strong>{mail.subject}</strong>
|
||||
</p>
|
||||
<div className="row" role="group" aria-label="Változat" style={{ gap: 4 }}>
|
||||
{(["html", "text"] as const).map((v) => (
|
||||
<button
|
||||
key={v}
|
||||
type="button"
|
||||
className={view === v ? "btn btn-sm" : "btn btn-sm btn-ghost"}
|
||||
aria-pressed={view === v}
|
||||
onClick={() => setView(v)}
|
||||
>
|
||||
{v === "html" ? "HTML" : "Szöveges"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{view === "html" ? (
|
||||
<iframe title="A levél HTML-változata" className="mail-frame" srcDoc={mail.html} sandbox="" />
|
||||
) : (
|
||||
<pre className="mail-text">{mail.text}</pre>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function InvitationList({ invitations, onChange }: { invitations: AdminInvitation[]; onChange: () => Promise<void> }) {
|
||||
return (
|
||||
<section className="card" aria-labelledby="invitations-title">
|
||||
<h2 id="invitations-title" style={{ marginTop: 0 }}>
|
||||
Meghívók
|
||||
</h2>
|
||||
{invitations.length === 0 ? (
|
||||
<p className="muted">Még nincs meghívó.</p>
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Cím</th>
|
||||
<th scope="col">Állapot</th>
|
||||
<th scope="col">Levél</th>
|
||||
<th scope="col">Küldve</th>
|
||||
<th scope="col">Lejár</th>
|
||||
<th scope="col">
|
||||
<span className="sr-only">Műveletek</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{invitations.map((i) => (
|
||||
<InvitationRow key={i.id} invitation={i} onChange={onChange} />
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function InvitationRow({ invitation: i, onChange }: { invitation: AdminInvitation; onChange: () => Promise<void> }) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
const [url, setUrl] = useState<string | null>(null);
|
||||
|
||||
async function act(kind: "resend" | "revoke") {
|
||||
if (kind === "revoke" && !window.confirm(`Visszavonod a meghívót (${i.email})?`)) return;
|
||||
setBusy(true);
|
||||
setNote(null);
|
||||
try {
|
||||
if (kind === "resend") {
|
||||
const res = await api<{ url: string }>(`/admin/invitations/${i.id}/resend`, { body: {} });
|
||||
setUrl(res.url);
|
||||
} else {
|
||||
await api(`/admin/invitations/${i.id}`, { method: "DELETE" });
|
||||
}
|
||||
await onChange();
|
||||
} catch (e) {
|
||||
setNote(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<td>
|
||||
<div>{i.email}</div>
|
||||
{i.message && (
|
||||
<div className="hint invite-msg" title={i.message}>
|
||||
„{i.message}”
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<span className={`badge invite-${i.status}`}>{STATUS[i.status]}</span>
|
||||
{i.accepted_by && <div className="hint">{i.accepted_by}</div>}
|
||||
</td>
|
||||
<td>
|
||||
<span className={i.mail === "failed" ? "msg-error" : i.mail === "queued" ? "muted" : undefined}>
|
||||
{MAIL[i.mail]}
|
||||
</span>
|
||||
{i.mail_error && <div className="hint">{i.mail_error.slice(0, 120)}</div>}
|
||||
</td>
|
||||
<td className="num">
|
||||
{formatDate(i.last_sent_at)}
|
||||
{i.sent_count > 1 && <div className="hint">{i.sent_count}× küldve</div>}
|
||||
</td>
|
||||
<td className="num">{i.status === "pending" || i.status === "expired" ? formatDate(i.expires_at) : "–"}</td>
|
||||
<td>
|
||||
<div className="row" style={{ gap: 4, flexWrap: "nowrap", justifyContent: "flex-end" }}>
|
||||
{url && <CopyLink url={url} />}
|
||||
{i.can_resend && (
|
||||
<button type="button" className="btn btn-sm" onClick={() => act("resend")} disabled={busy}>
|
||||
Újraküldés
|
||||
</button>
|
||||
)}
|
||||
{(i.status === "pending" || i.status === "expired") && (
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => act("revoke")} disabled={busy}>
|
||||
Visszavonás
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{note && (
|
||||
<div className="msg-error" role="alert" style={{ fontSize: 13 }}>
|
||||
{note}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
function WaitlistTable({ waitlist, onChange }: { waitlist: WaitlistEntry[]; onChange: () => Promise<void> }) {
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
|
||||
async function invite(w: WaitlistEntry) {
|
||||
setBusy(w.email);
|
||||
setNote(null);
|
||||
try {
|
||||
const res = await api<{ results: InvitationResult[] }>("/admin/invitations", {
|
||||
body: { emails: [w.email], locale: w.locale },
|
||||
});
|
||||
const r = res.results[0];
|
||||
if (r && r.status !== "invited") setNote(`${r.email}: ${RESULT[r.status]}`);
|
||||
await onChange();
|
||||
} catch (e) {
|
||||
setNote(errorText(e));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(w: WaitlistEntry) {
|
||||
setBusy(w.email);
|
||||
setNote(null);
|
||||
try {
|
||||
await api(`/admin/waitlist/${encodeURIComponent(w.email)}`, { method: "DELETE" });
|
||||
await onChange();
|
||||
} catch (e) {
|
||||
setNote(errorText(e));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card" aria-labelledby="waitlist-title">
|
||||
<h2 id="waitlist-title" style={{ marginTop: 0 }}>
|
||||
Várólista
|
||||
</h2>
|
||||
<p className="hint">Akik meghívó nélkül próbáltak belépni, és kérték, hogy szóljunk nekik.</p>
|
||||
{note && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{note}
|
||||
</p>
|
||||
)}
|
||||
{waitlist.length === 0 ? (
|
||||
<p className="muted">Üres.</p>
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Cím</th>
|
||||
<th scope="col">Feliratkozott</th>
|
||||
<th scope="col">Meghívó</th>
|
||||
<th scope="col">
|
||||
<span className="sr-only">Műveletek</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{waitlist.map((w) => (
|
||||
<tr key={w.email}>
|
||||
<td>{w.email}</td>
|
||||
<td className="num">{formatDate(w.created_at)}</td>
|
||||
<td>{w.invitation === "pending" ? "elküldve" : w.invitation === "accepted" ? "elfogadva" : "–"}</td>
|
||||
<td>
|
||||
<div className="row" style={{ gap: 4, flexWrap: "nowrap", justifyContent: "flex-end" }}>
|
||||
{w.invitation === null && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm"
|
||||
onClick={() => invite(w)}
|
||||
disabled={busy !== null}
|
||||
>
|
||||
Meghívás
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm btn-ghost"
|
||||
onClick={() => remove(w)}
|
||||
disabled={busy !== null}
|
||||
>
|
||||
Törlés
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AdminNav } from "@/components/AdminNav";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
import { AdminInvitations } from "./AdminInvitations";
|
||||
|
||||
export const metadata: Metadata = { title: "Meghívók" };
|
||||
|
||||
export default async function AdminInvitationsPage() {
|
||||
const me = await requireMe("/admin/meghivok");
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin/meghivok" />
|
||||
<div className="page-head">
|
||||
<h1>Meghívók</h1>
|
||||
<p className="muted">
|
||||
Az oldalra csak meglévő felhasználó vagy meghívott léphet be. A meghívó 30 napig érvényes, és a linkkel bármelyik
|
||||
Google-fiókkal elfogadható.
|
||||
</p>
|
||||
</div>
|
||||
<AdminInvitations />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import Script from "next/script";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { Waitlist } from "@/components/Waitlist";
|
||||
import { ApiError, api, errorText } from "@/lib/api";
|
||||
|
||||
/** Google's "G" mark (branding guidelines: unmodified, on the left of the label). */
|
||||
function GoogleMark() {
|
||||
@@ -30,32 +31,57 @@ function GoogleMark() {
|
||||
);
|
||||
}
|
||||
|
||||
/** The e-mail address inside Google's ID token (only for prefilling a form; the backend verifies the token). */
|
||||
function tokenEmail(credential: string): string {
|
||||
try {
|
||||
const part = credential.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
||||
const bytes = Uint8Array.from(atob(part), (c) => c.charCodeAt(0));
|
||||
const email = JSON.parse(new TextDecoder().decode(bytes)).email;
|
||||
return typeof email === "string" ? email : "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "Continue with Google" in the site's own button style. Google's real
|
||||
* (rendered, invisible) button lies on top of it and receives the click, so
|
||||
* the sign-in still returns an ID token.
|
||||
*/
|
||||
export function GoogleLogin({ clientId, target }: { clientId: string; target: string }) {
|
||||
export function GoogleLogin({
|
||||
clientId,
|
||||
target,
|
||||
inviteToken = null,
|
||||
}: {
|
||||
clientId: string;
|
||||
target: string;
|
||||
/** From an invitation link: lets in any Google account. */
|
||||
inviteToken?: string | null;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const slot = useRef<HTMLDivElement>(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
/** Set when the address has no invitation: offer the waitlist for it. */
|
||||
const [uninvited, setUninvited] = useState<string | null>(null);
|
||||
|
||||
const onCredential = useCallback(
|
||||
async (response: GoogleCredentialResponse) => {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setUninvited(null);
|
||||
try {
|
||||
await api("/auth/google", { body: { id_token: response.credential } });
|
||||
await api("/auth/google", { body: { id_token: response.credential, invite_token: inviteToken } });
|
||||
router.replace(target);
|
||||
router.refresh();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
if (e instanceof ApiError && e.code === "not_invited") setUninvited(tokenEmail(response.credential));
|
||||
else setError(errorText(e));
|
||||
setBusy(false);
|
||||
}
|
||||
},
|
||||
[router, target],
|
||||
[router, target, inviteToken],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -94,6 +120,16 @@ export function GoogleLogin({ clientId, target }: { clientId: string; target: st
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{uninvited !== null && (
|
||||
<>
|
||||
<p className="msg msg-error" role="alert">
|
||||
{inviteToken
|
||||
? "Ez a meghívó már nem érvényes, és ehhez a Google-fiókhoz sem tartozik másik."
|
||||
: `A Sorsfonalak jelenleg meghívásos, és ${uninvited ? `a(z) ${uninvited} címhez` : "ehhez a fiókhoz"} nem tartozik meghívó. Ha kaptál meghívót egy másik címre, lépj be azzal a Google-fiókkal, vagy nyisd meg a levélben kapott linket.`}
|
||||
</p>
|
||||
<Waitlist email={uninvited} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import { redirect } from "next/navigation";
|
||||
import { Logo } from "@/components/SiteHeader";
|
||||
import { ZodiacWheel } from "@/components/ZodiacWheel";
|
||||
import { BACKEND_URL, getMe } from "@/lib/server";
|
||||
import type { PublicConfig } from "@/lib/types";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { InvitationLanding, PublicConfig } from "@/lib/types";
|
||||
|
||||
import { GoogleLogin } from "./GoogleLogin";
|
||||
|
||||
@@ -26,11 +27,63 @@ async function loadConfig(): Promise<PublicConfig | null> {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadInvitation(token: string): Promise<InvitationLanding | null> {
|
||||
try {
|
||||
const res = await fetch(`${BACKEND_URL}/v1/public/invitations/${encodeURIComponent(token)}`, { cache: "no-store" });
|
||||
return res.ok ? ((await res.json()) as InvitationLanding) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const CLOSED: Record<string, string> = {
|
||||
accepted: "Ezt a meghívót már felhasználták. Ha a tiéd volt, egyszerűen lépj be ugyanazzal a Google-fiókkal.",
|
||||
expired: "Ez a meghívó lejárt. Kérj újat attól, aki meghívott.",
|
||||
revoked: "Ezt a meghívót visszavonták.",
|
||||
};
|
||||
|
||||
/** The invitation the visitor came with: who sent it and what they wrote. */
|
||||
function InvitationCard({ invitation }: { invitation: InvitationLanding | null }) {
|
||||
if (!invitation) {
|
||||
return (
|
||||
<p className="msg msg-error" role="alert">
|
||||
Ez a meghívólink érvénytelen. Ellenőrizd, hogy a teljes linket nyitottad-e meg a levélből.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
if (invitation.status !== "pending") {
|
||||
return (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{CLOSED[invitation.status]}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="card invite-card">
|
||||
<span className="eyebrow">Meghívó</span>
|
||||
<p style={{ margin: 0 }}>
|
||||
{invitation.inviter_name ? <strong>{invitation.inviter_name}</strong> : "Valaki"} meghívott a Sorsfonalakra.
|
||||
</p>
|
||||
{invitation.message && <blockquote className="invite-quote">{invitation.message}</blockquote>}
|
||||
<p className="hint" style={{ margin: 0 }}>
|
||||
Bármelyik Google-fiókoddal elfogadhatod. Érvényes: {formatDate(invitation.expires_at).replace(/\.$/, "")}-ig.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default async function LoginPage({ searchParams }: { searchParams: Promise<Record<string, string | string[]>> }) {
|
||||
const target = safeTarget((await searchParams).vissza);
|
||||
const params = await searchParams;
|
||||
const target = safeTarget(params.vissza);
|
||||
if (await getMe()) redirect(target);
|
||||
const config = await loadConfig();
|
||||
const rawToken = Array.isArray(params.meghivo) ? params.meghivo[0] : params.meghivo;
|
||||
const inviteToken = rawToken && /^[A-Za-z0-9_-]{8,200}$/.test(rawToken) ? rawToken : null;
|
||||
const [config, invitation] = await Promise.all([
|
||||
loadConfig(),
|
||||
inviteToken ? loadInvitation(inviteToken) : Promise.resolve(null),
|
||||
]);
|
||||
const clientId = config?.google_login.enabled ? config.google_login.client_id : null;
|
||||
const inviteOnly = config?.signup_mode === "invite";
|
||||
|
||||
return (
|
||||
<div className="auth">
|
||||
@@ -47,21 +100,32 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis
|
||||
<main className="auth-main">
|
||||
<div className="auth-box">
|
||||
<div className="page-head">
|
||||
<h1 style={{ fontSize: 44 }}>Belépés</h1>
|
||||
<p className="muted">Üdv újra! Lépj be a fiókodba.</p>
|
||||
<h1 style={{ fontSize: 44 }}>{rawToken ? "Meghívó" : "Belépés"}</h1>
|
||||
<p className="muted">{rawToken ? "Lépj be, és már kezdheted is." : "Üdv újra! Lépj be a fiókodba."}</p>
|
||||
</div>
|
||||
{rawToken && <InvitationCard invitation={inviteToken ? invitation : null} />}
|
||||
{config === null ? (
|
||||
<p className="msg msg-error" role="alert">
|
||||
A szerver most nem érhető el. Próbáld újra egy kicsit később.
|
||||
</p>
|
||||
) : clientId ? (
|
||||
<GoogleLogin clientId={clientId} target={target} />
|
||||
<GoogleLogin
|
||||
clientId={clientId}
|
||||
target={target}
|
||||
inviteToken={invitation?.status === "pending" ? inviteToken : null}
|
||||
/>
|
||||
) : (
|
||||
<p className="msg msg-error" role="alert">
|
||||
A Google-belépés még nincs beállítva (a backend <code>GOOGLE_CLIENT_IDS</code> változója üres).
|
||||
</p>
|
||||
)}
|
||||
<p className="auth-foot">Még nincs fiókod? Az első belépéskor létrejön.</p>
|
||||
<p className="auth-foot">
|
||||
{rawToken
|
||||
? "A fiókod az első belépéskor jön létre."
|
||||
: inviteOnly
|
||||
? "Az oldal jelenleg meghívásos: új fiók csak meghívóval jön létre."
|
||||
: "Még nincs fiókod? Az első belépéskor létrejön."}
|
||||
</p>
|
||||
<p className="hint">
|
||||
A belépéssel elfogadod, hogy a születési adataidat a képleted kiszámításához tároljuk. Bármikor törölheted
|
||||
őket a profilodban. Részletek: <Link href="/adatvedelem">adatvédelmi tájékoztató</Link>.
|
||||
|
||||
@@ -549,3 +549,22 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.pkg-grid, .pkg-grid-compact { grid-template-columns: 1fr; }
|
||||
.pkg-tagline { min-height: 0; }
|
||||
}
|
||||
|
||||
/* Invitations */
|
||||
.invite-card { display: flex; flex-direction: column; gap: 8px; }
|
||||
.invite-quote {
|
||||
margin: 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--gold);
|
||||
font-style: italic; white-space: pre-line; color: var(--ink);
|
||||
}
|
||||
.waitlist { display: flex; flex-direction: column; gap: 10px; }
|
||||
.invite-results { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
|
||||
.invite-results li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.invite-msg { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.invite-accepted { border-color: color-mix(in srgb, var(--ok) 50%, transparent); color: var(--ok); }
|
||||
.invite-pending { border-color: rgba(217, 180, 106, 0.5); color: var(--gold); }
|
||||
.invite-expired, .invite-revoked { color: var(--muted); }
|
||||
.mail-frame { width: 100%; height: 640px; border: 1px solid var(--line); border-radius: 8px; background: #f4f1ea; }
|
||||
.mail-text {
|
||||
margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 8px; max-height: 640px; overflow: auto;
|
||||
white-space: pre-wrap; font-size: 13px; line-height: 1.5;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
|
||||
// A button, not an automatic request: link scanners of mail providers open
|
||||
// every link, and they must not unsubscribe anyone.
|
||||
export function Unsubscribe({ token }: { token: string | null }) {
|
||||
const [state, setState] = useState<"idle" | "busy" | "done">("idle");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
if (!token) {
|
||||
return (
|
||||
<p className="msg msg-error" role="alert">
|
||||
Hiányzik a link vége. Nyisd meg a teljes linket a levélből.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
if (state === "done") {
|
||||
return (
|
||||
<p className="msg msg-ok" role="status">
|
||||
Leiratkoztál: erre a címre nem küldünk több meghívót.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
async function confirm() {
|
||||
setState("busy");
|
||||
setError(null);
|
||||
try {
|
||||
await api(`/public/invitations/unsubscribe?token=${encodeURIComponent(token!)}`, { method: "POST" });
|
||||
setState("done");
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
setState("idle");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card field" style={{ gap: 12 }}>
|
||||
<p style={{ margin: 0 }}>
|
||||
Ha leiratkozol, erre az e-mail-címre többé nem küldünk meghívót, és a mostani meghívód is érvényét veszti.
|
||||
</p>
|
||||
<div>
|
||||
<button type="button" className="btn btn-primary" onClick={confirm} disabled={state === "busy"}>
|
||||
{state === "busy" ? "Leiratkozás…" : "Leiratkozom"}
|
||||
</button>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { Metadata } from "next";
|
||||
|
||||
import { Unsubscribe } from "./Unsubscribe";
|
||||
|
||||
export const metadata: Metadata = { title: "Leiratkozás", robots: { index: false } };
|
||||
|
||||
/** "No more invitations", from the link in the footer of an invitation e-mail. */
|
||||
export default async function UnsubscribePage({ searchParams }: { searchParams: Promise<Record<string, string | string[]>> }) {
|
||||
const raw = (await searchParams).token;
|
||||
const token = Array.isArray(raw) ? raw[0] : raw;
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 560 }}>
|
||||
<div className="page-head">
|
||||
<h1>Leiratkozás</h1>
|
||||
<p className="muted">Nem kérsz több meghívót a Sorsfonalakra.</p>
|
||||
</div>
|
||||
<Unsubscribe token={token ?? null} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
/** The link in the invitation e-mail: the login page shows the invitation. */
|
||||
export default async function InvitationLink({ params }: { params: Promise<{ token: string }> }) {
|
||||
const { token } = await params;
|
||||
redirect(`/belepes?meghivo=${encodeURIComponent(token)}`);
|
||||
}
|
||||
Reference in New Issue
Block a user