From e00c820d2fe6ee1d5cf0944b51d371c523f79db0 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 10 Nov 2026 08:29:00 -0600 Subject: [PATCH] Earners Corner invites credit the inviter (Marty 2026-11-10): /forum/join/[?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 --- qa/forumsso.mjs | 13 +++++++++++++ server.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/qa/forumsso.mjs b/qa/forumsso.mjs index a9451e0..aba3060 100644 --- a/qa/forumsso.mjs +++ b/qa/forumsso.mjs @@ -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')); diff --git a/server.js b/server.js index 4519dd8..c4059b7 100644 --- a/server.js +++ b/server.js @@ -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/[?to=/path] sets the member as sponsor + // exactly like /join/ (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 => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); + const body = 'Your Earners Corner invite link' + + '

Your Earners Corner invite link

' + + (un ? '

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.

' + + '

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.

' + : '

Pick a username in your InstantAdPay profile first, then come back here for your invite link.

Open your profile

') + + '

Back to Earners Corner

'; + 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);