Earners Corner invites credit the inviter (Marty 2026-11-10): /forum/join/<username>[?to=/path] sets the member as sponsor exactly like /join/ (30-day cookie, last touch wins, first-touch source earnerscorner.com, link view recorded) and forwards to the forum (?to= must be an on-forum path); /forum/invite shows a signed-in member their link. The forum's Log In carries a shared thread's ?u= through this route. qa/forumsso 14/14 (incl. a new sign-up landing under the inviter); member walk 0 bugs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-10 08:29:00 -06:00
parent ef28c16502
commit e00c820d2f
2 changed files with 47 additions and 0 deletions
+13
View File
@@ -53,6 +53,19 @@ try {
ok(pl.get('nonce') === 'abc123' && pl.get('email') === 'fs-a@example.com' && pl.get('external_id') === 'fs-a@example.com' && pl.get('username') === 'forumfan', 'payload: nonce, email, external id, username', pl.toString().slice(0, 200));
ok(pl.get('website') === 'https://stackpol.com/forumfan' && (pl.get('remove_groups') || '').includes('network_members'), 'free member: no network_members group, profile links their Stack POL page');
r = await get('/forum/sso?sso=' + encodeURIComponent(sso) + '&sig=' + sig(sso), { Cookie: h.Cookie }); ok(r.status === 302 && (r.headers.get('location') || '').startsWith('https://earnerscorner.com/session/sso_login?sso='), 'already signed in -> straight back');
// invite link + shared-thread credit (2026-11-10)
r = await get('/forum/join/forumfan?to=' + encodeURIComponent('/t/some-thread/23?u=forumfan'));
const ick = (r.headers.getSetCookie ? r.headers.getSetCookie() : []).map(c => c.split(';')[0]);
ok(r.status === 302 && r.headers.get('location') === 'https://earnerscorner.com/t/some-thread/23?u=forumfan' && ick.includes('iap.sponsor=forumfan'), 'invite link sets the member as sponsor and forwards to the thread', JSON.stringify(ick));
r = await get('/forum/join/nosuchperson'); ok(r.status === 302 && !(r.headers.getSetCookie ? r.headers.getSetCookie() : []).some(c => c.startsWith('iap.sponsor=')), 'unknown username: forwards, sets no sponsor');
r = await get('/forum/join/forumfan?to=' + encodeURIComponent('//evil.example/x')); ok(r.headers.get('location') === 'https://earnerscorner.com/', 'off-site ?to= is refused');
const inv = await fetch(B + '/forum/invite', { headers: { Cookie: h.Cookie } }); const ih = await inv.text();
ok(inv.status === 200 && ih.includes('https://instantadpay.com/forum/join/forumfan'), 'invite page shows the member their link');
const nb = await fetch(B + '/api/auth/email/start', { method: 'POST', headers: { 'Content-Type': 'application/json', Cookie: 'iap.sponsor=forumfan' }, body: JSON.stringify({ email: 'fs-new@example.com', fts: Date.now() - 5000 }) }); const nbj = await nb.json();
const nv = await fetch(B + '/api/auth/email/verify', { method: 'POST', headers: { 'Content-Type': 'application/json', Cookie: 'iap.sponsor=forumfan' }, body: JSON.stringify({ email: 'fs-new@example.com', code: nbj.devCode }) });
const nck = (nv.headers.getSetCookie ? nv.headers.getSetCookie() : []).map(c => c.split(';')[0]).join('; ');
const nme = await api('/api/me', null, { Cookie: nck + '; iap.sponsor=forumfan' });
ok(nme.j && (nme.j.sponsorName === '@forumfan' || String(nme.j.sponsorRef || '').toLowerCase() === 'forumfan' || JSON.stringify(nme.j).includes('forumfan')), 'a new sign-up through the forum invite lands under the inviter', JSON.stringify(nme.j && { sponsorName: nme.j.sponsorName, sponsorRef: nme.j.sponsorRef }));
} catch (e) { console.log('FAIL exception', e && e.stack || e); fails++; }
finally { try { srv.kill(); } catch (e) {} try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {} }
if (fails) console.log(log.split('\n').filter(l => /forum|error/i.test(l)).slice(-15).join('\n'));
+34
View File
@@ -3935,6 +3935,40 @@ const server = http.createServer(async (req, res) => {
}
// -- Earners Corner forum sign-in (2026-11-10): Discourse sends /forum/sso; a signed-out visitor signs in on /my first (the request
// rides in a 30-minute cookie) and /api/my/forum finishes the hand-back. See forumsso.js.
// -- Earners Corner invite + shared-thread credit (Marty 2026-11-10): /forum/join/<username>[?to=/path] sets the member as sponsor
// exactly like /join/<username> (30-day cookie, last touch wins, first-touch source recorded), then forwards to the forum. A
// visitor who later signs in on the forum creates their InstantAdPay account here, so the sponsor cookie is already in place.
// /forum/invite shows a signed-in member their own forum invite link.
m = /^\/forum\/join\/([A-Za-z0-9_]{1,20})$/.exec(p);
if (m && (req.method === 'GET' || req.method === 'HEAD')) {
const to = String(u.searchParams.get('to') || '/'); const path = /^\/(?!\/)[\w\-./?=&%]*$/.test(to) ? to : '/';
const a = await accounts.byUsername(m[1].toLowerCase());
const set = [];
if (a && a.username && !fraud.isSuspended(a.email)) {
const cookieTail = `; Path=/; SameSite=Lax; Max-Age=${30 * 24 * 3600}${IS_PROD ? '; Secure' : ''}`;
set.push('iap.sponsor=' + a.username + cookieTail); // last touch wins, same as /join/
if (!parseCookies(req)['iap.ref']) set.push('iap.ref=' + encodeURIComponent('earnerscorner.com') + cookieTail);
if (req.method === 'GET') coach.recordView(a.username, '', 'https://earnerscorner.com/');
}
res.writeHead(302, baseHeaders(Object.assign({ Location: forumsso.FORUM_URL() + path, 'Cache-Control': 'no-store' }, set.length ? { 'Set-Cookie': set } : {}))); return res.end();
}
if (p === '/forum/invite' && req.method === 'GET') {
const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: forumsso.FORUM_URL() + '/session/sso', 'Cache-Control': 'no-store' }); return res.end(); }
const a = await accounts.byEmail(s.email); const un = a && a.username;
const link = un ? 'https://instantadpay.com/forum/join/' + un : '';
const esc = x => String(x).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
const body = '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Your Earners Corner invite link</title>'
+ '<style>body{margin:0;font:16px/1.55 system-ui,-apple-system,Segoe UI,sans-serif;background:#13101f;color:#efeafb;display:grid;place-items:center;min-height:100vh;padding:16px}'
+ '.c{max-width:560px;width:100%;background:#1c1830;border:1px solid #2f2947;border-radius:16px;padding:24px}h1{font-size:22px;margin:0 0 6px}p{color:#bdb5d6;margin:0 0 14px}'
+ 'input{width:100%;box-sizing:border-box;font:600 15px ui-monospace,Consolas,monospace;padding:12px;border-radius:10px;border:1px solid #6d28d9;background:#0f0c1a;color:#fff}'
+ 'a{color:#f5b74a}.s{font-size:13px;margin-top:14px}</style></head><body><div class="c"><h1>Your Earners Corner invite link</h1>'
+ (un ? '<p>Share this link. Anyone who joins the forum through it, or through a thread you share while signed in, signs up with you as their sponsor, exactly like your InstantAdPay referral link.</p>'
+ '<input readonly value="' + esc(link) + '" aria-label="Your invite link"><p class="s">Tap the box, select all and copy. To share one thread, use the share button under any post while you are signed in to the forum: those links carry your name too.</p>'
: '<p>Pick a username in your InstantAdPay profile first, then come back here for your invite link.</p><p><a href="/my#profile">Open your profile</a></p>')
+ '<p class="s"><a href="' + esc(forumsso.FORUM_URL()) + '/">Back to Earners Corner</a></p></div></body></html>';
res.writeHead(200, baseHeaders({ 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' })); return res.end(body);
}
if ((p === '/forum/sso' || p === '/api/my/forum') && req.method === 'GET') {
const raw = p === '/forum/sso' ? { sso: u.searchParams.get('sso'), sig: u.searchParams.get('sig') } : (() => { const c = String(parseCookies(req)['iap.forumsso'] || ''); const i = c.lastIndexOf('.'); return { sso: c.slice(0, i), sig: c.slice(i + 1) }; })();
const v = forumsso.verify(raw.sso, raw.sig);