diff --git a/server.js b/server.js index 8614f16..4f14995 100644 --- a/server.js +++ b/server.js @@ -185,6 +185,7 @@ function chatLimited(ip) { } // magic-code sign-in: emailLower -> {code, exp, tries} const emailCodes = new Map(); +const inviteTokens = new Map(); // admin-minted one-time sign-in links for testers: token -> {email, exp, next} // ── sign-up code guard (Marty, 2026-09-11): the email box is one field and one // tap, so nothing visible stands in a human's way. Bots hit four invisible walls: // a honeypot field, a minimum form age, per-IP + global send limits, and, only @@ -894,6 +895,14 @@ const server = http.createServer(async (req, res) => { } if (p === '/api/zone/seen' && (req.method === 'GET' || req.method === 'POST')) { await zones.seen(u.searchParams.get('i'), req); res.writeHead(204, { 'Access-Control-Allow-Origin': '*' }); return res.end(); } { const zm = /^\/api\/zone\/click\/([a-f0-9]{12})$/.exec(p); if (zm && req.method === 'GET') { const target = await zones.click(zm[1]); res.writeHead(302, { Location: target || '/', 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer-when-downgrade' }); return res.end(); } } + { const wm = /^\/welcome\/([a-f0-9]{48})$/.exec(p); if (wm && req.method === 'GET') { // one-time tester sign-in link + const t = inviteTokens.get(wm[1]); + if (!t || t.exp < Date.now()) { inviteTokens.delete(wm[1]); res.writeHead(410, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end('Link used

That sign-in link was already used or has expired. Ask for a fresh one.

'); } + inviteTokens.delete(wm[1]); + const acct = await accounts.byEmail(t.email); let memberId = 0; if (acct && acct.address) { try { memberId = await chain.memberIdByAccount(acct.address); } catch (e) {} } + const token = await auth.mintSession({ email: t.email, address: (acct && acct.address) || null, memberId }); + res.writeHead(302, { 'Set-Cookie': auth.sessionCookie(token), Location: t.next || '/ads', 'Cache-Control': 'no-store' }); return res.end(); + } } // -- member pages: /p/ on the app host and on every link domain; the lead form and the hit beacon live beside it let pm = /^\/p\/([a-z0-9-]{3,60})$/i.exec(p); if (pm && (req.method === 'GET' || req.method === 'HEAD')) { @@ -1869,6 +1878,17 @@ const server = http.createServer(async (req, res) => { const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); const r = await zones.update(s.email, m[1], await readBody(req)); return json(res, r.error ? 400 : 200, r); } + // tester invite: an admin-minted one-time sign-in link (24 h). Creates the account if needed, bypasses the sign-up + // gate and needs no email, which is what a curtained test app without outbound mail needs (2026-09-29) + if (p === '/api/admin/invite' && req.method === 'POST') { + if (!isAdmin(req)) return json(res, 401, { error: 'Admin only.' }); + const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); + if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(e)) return json(res, 400, { error: 'Which email?' }); + const r = await accounts.ensure(e, '', '', null); if (r.error) return json(res, 400, r); + const token = crypto.randomBytes(24).toString('hex'); + inviteTokens.set(token, { email: e, exp: Date.now() + 24 * 3600 * 1000, next: /^\/[a-z]/.test(String(b.next || '')) ? String(b.next) : '/ads' }); + return json(res, 200, { ok: true, url: 'https://' + SITE_HOST + '/welcome/' + token, created: !!r.created }); + } if (p === '/api/admin/zones' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'Admin only.' }); return json(res, 200, { zones: await zones.adminList(), totals: zones.totals(), rates: zones.settings(), warmup: zones.WARMUP, holdRatio: zones.HOLD_RATIO }, { 'Cache-Control': 'no-store' });