Site invite module: email-check code mail for Video App Income's network gate (/api/partner/invite/code: fixed wording, no links, requested = transactional, 5 an hour per address, 2,000 a day; typo and throwaway domains refused); mailer.send opts.fromName = the site's name on the same authenticated address; chatbot answer extended (Marty 2026-11-21: every Video App Income member must be a network member, as frictionless as possible)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-21 07:42:51 -06:00
parent 1d5dd057e0
commit 50bd2e3557
5 changed files with 43 additions and 5 deletions
+25 -1
View File
@@ -9,6 +9,9 @@
// -> { ok, sender: username, directs: [{ username, state: 'ok' | 'sent' | 'no' }], left: { sender, network }, paused }
// POST /api/partner/invite/send { rid, site, sender, items: [{ username, link }], note? }
// -> { ok, results: [{ username, status: 'sent' | <refusal code> }], sent, left }
// POST /api/partner/invite/code { site, email, code } -> { ok } | { error, code } (2026-11-21)
// the email-check code for the site's network gate: the SITE makes and checks the 6-digit code, this app only mails it
// (a requested code is transactional, like a sign-in code). Fixed wording, no links; 5 an hour per address, 2,000 a day in all.
// Signature: X-Invite-Ts (ms) + X-Invite-Sig = hex HMAC-SHA256(SITE_INVITE_SECRET, 'invite.v1.' + ts + '\n' + raw body), 5 minutes.
//
// The rules:
@@ -184,7 +187,28 @@ async function send(b) {
console.log('site invite', siteId, 'from', sender.username, 'sent', sentN, 'of', items.length);
return { ok: true, results, sent: sentN, left: await left(sender) };
}
async function handle(op, b) { if (op === 'eligible') return eligible(b || {}); if (op === 'send') return send(b || {}); return { error: 'unknown op' }; }
// ---- the email-check code a site asks for when a new person gives their email at its network gate ----
const codeLog = new Map(); let codeDay = { start: 0, n: 0 };
async function code(b) {
const site = SITES[lc(b.site)]; if (!site) return { error: 'unknown site', code: 'site' };
const em = lc(b.email), c = String(b.code || '');
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(em) || em.length > 190 || !/^\d{6}$/.test(c)) return { error: 'That does not look like an email address.', code: 'email' };
const d = em.split('@')[1] || '';
if (THROWAWAY.has(d)) return { error: 'Please use your regular email address, not a temporary one.', code: 'email' };
if (R.hooks && R.hooks.suggestDomain) { const fix = R.hooks.suggestDomain(d); if (fix && fix !== d) return { error: 'Check the spelling of your email. Did you mean ' + em.split('@')[0] + '@' + fix + '?', code: 'email' }; }
if (R.hooks && R.hooks.excluded && R.hooks.excluded(em)) return { error: 'That email cannot be used here.', code: 'email' };
if (R.hooks && R.hooks.erased && R.hooks.erased(em)) return { error: 'That email cannot be used here.', code: 'email' };
if (!R.mailer || !R.mailer.hasKey()) return { error: 'Email is not available right now.', code: 'mail' };
const now = clock(), day = dayStart(now); if (codeDay.start !== day) codeDay = { start: day, n: 0 };
const mine = (codeLog.get(em) || []).filter(t => now - t < 3600000);
if (mine.length >= 5) return { error: 'Too many codes were sent to that address. Try again in an hour.', code: 'limit' };
if (codeDay.n >= 2000) return { error: 'Please try again later.', code: 'limit' };
mine.push(now); codeLog.set(em, mine); codeDay.n++; if (codeLog.size > 20000) codeLog.clear();
const text = 'Your code is: ' + c + '\n\nEnter it in ' + site.name + ' to confirm your email. It works for 15 minutes. If you did not ask for it, ignore this email.\n\n' + site.name + ' is part of the Crypto Team Build Network. This email was sent by InstantAdPay, the mail service of the network.';
try { await R.mailer.send(em, c + ' is your ' + site.name + ' code', text, null, { transactional: true, fromName: site.name }); } catch (e) { console.error('site code mail', e.message); return { error: 'The email could not be sent. Check the address and try again.', code: 'mail' }; }
return { ok: true };
}
async function handle(op, b) { if (op === 'eligible') return eligible(b || {}); if (op === 'send') return send(b || {}); if (op === 'code') return code(b || {}); return { error: 'unknown op' }; }
async function adminView() { const since = dayStart(clock()), c = cfg(); return { on: enabled(), paused: c.paused, perSender: c.perSender, perDay: c.perDay, today: await S().count(since), recent: (await S().recent(200)).map(r => ({ site: r.site, to: r.username, from: r.senderName, ts: r.ts, status: r.status, link: r.link })) }; }
// one sample to one address, for the owner to read before the feature opens. Not counted, not recorded.
async function sample(to, siteId) { const site = SITES[lc(siteId) || 'videoappincome']; if (!site) return { error: 'unknown site' }; const m = compose(site, 'yoursponsor', 'yourname', 'https://' + hosts()[0] + '/p/faceless', ''); await R.mailer.send(to, '[SAMPLE] ' + m.subject, m.text, m.html); return { ok: true, to, subject: m.subject, text: m.text }; }