1a13f53b9c
Login ad: shown on the next member page load whenever the member's last finished view on this site is older than loginAdEveryHours (site setting, default 3), signed in just now or not. One row per member in MySQL (loginadclock.js, table login_ad_views; the same file in LinkSpin): /api/ads/slot?type=login answers notDue inside the window and marks the serve; POST /api/ads/login/seen at the end of the countdown restarts the clock only if the serve was at least dwell-2 s earlier (a reload during the countdown does not skip it). Framed gate, 10 s timer, click relay, frameable fallback, delivery and credit accounting unchanged. Welcome tour still outranks it. Member erase forgets the row. Admin site setting label added. 5xYourTeam loop: IAP answered /sso/check?r=fivex as if LinkSpin asked (fivex was missing from the wallets map), so tokens went to LinkSpin and Marty never got back. fivex added (FIVEX_URL, default https://5xyourteam.com); networksso.js now refuses an unknown r instead of answering as the peer. A pending network hop (nsso.back) is finished after sign-in: the login ad (if due) then /sso/resume; the gate's finish button says Continue and goes back to the site and page the member came from. /api/me carries nssoBack. The session pop-up (welcome.js) waits until the login gate is closed. networksso.js: loop guard TRIED_AGE 30 min -> 120 s (it blocked Marty's silent sign-in on LinkSpin), NAMES gains fivex. The same file now ships byte-identical in IAP, LinkSpin, VBB, DLB, ViralAdBlitz, DownlineHydra, 5xYourTeam. Tests: qa/networksso-partner.e2e.mjs (new, in run.sh member): a stand-in wallet partner on its own host; signed in on IAP -> straight back with a session, no dashboard, no ad; signed out -> sign in, login ad, Continue -> back on the partner page; the clock (due, too-soon refused, no re-show on reload or another tab, reload during the countdown brings it back); LinkSpin -> partner. networksso unit test: 2-minute guard, unknown site gets nothing. qa member: ALL PASSED (2 known admin warnings). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
4.3 KiB
JavaScript
77 lines
4.3 KiB
JavaScript
// Login-ad clock (Marty 2026-11-15): "I definitely don't want somebody to not look at a login ad for 7 days... if login ads are
|
|
// available on those sites, they need to be seen several times a day." The SAME file ships in InstantAdPay and LinkSpin.
|
|
//
|
|
// A member sees the login ad on their next member-area page load whenever their last finished login-ad view on THIS site is more
|
|
// than loginAdEveryHours old (site setting, default 3), whether or not they just signed in. One row per member in MySQL
|
|
// (table login_ad_views: k = lowercased email, or 'w:' + wallet for a wallet-only session; seen_at; served_at).
|
|
// due(k) true when the member should get the login ad now (no row, or seen_at older than the setting)
|
|
// served(k) the login ad was handed to this member (the countdown starts on their screen)
|
|
// seen(k, s) the countdown ended: counts only when a serve to this member happened at least s - 2 seconds ago and within the
|
|
// last 30 minutes, so reloading during the countdown never skips the ad
|
|
// forget(k) member erase
|
|
// No database (local QA): the same rules in memory. A failed database read answers "due": when in doubt the ad shows.
|
|
'use strict';
|
|
|
|
let pool = null, tableReady = null, hours = () => 3;
|
|
const mem = new Map(); // k -> { seen, served }
|
|
const SERVE_WINDOW = 30 * 60 * 1000;
|
|
|
|
const keyOf = s => {
|
|
if (!s) return '';
|
|
const e = String(s.email || '').trim().toLowerCase();
|
|
if (e) return e.slice(0, 190);
|
|
const a = String(s.address || '').trim().toLowerCase();
|
|
return /^0x[0-9a-f]{40}$/.test(a) ? 'w:' + a : '';
|
|
};
|
|
const everyMs = () => { const h = Number(hours()); return (Number.isFinite(h) && h > 0 ? Math.min(h, 24 * 30) : 3) * 3600 * 1000; };
|
|
|
|
function init(opts) {
|
|
const o = opts || {};
|
|
if (typeof o.hours === 'function') hours = o.hours;
|
|
const url = String(o.url || '').trim();
|
|
pool = null; tableReady = null; mem.clear();
|
|
if (url) { const mysql = require('mysql2/promise'); pool = mysql.createPool({ uri: url, connectionLimit: 3, charset: 'utf8mb4' }); }
|
|
}
|
|
async function table() {
|
|
if (!tableReady) tableReady = pool.query('CREATE TABLE IF NOT EXISTS login_ad_views (k VARCHAR(200) PRIMARY KEY, seen_at BIGINT NOT NULL DEFAULT 0, served_at BIGINT NOT NULL DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4').catch(e => { tableReady = null; throw e; });
|
|
return tableReady;
|
|
}
|
|
async function row(k) {
|
|
if (!pool) return mem.get(k) || null;
|
|
await table();
|
|
const [r] = await pool.query('SELECT seen_at, served_at FROM login_ad_views WHERE k = ?', [k]);
|
|
return r[0] ? { seen: Number(r[0].seen_at) || 0, served: Number(r[0].served_at) || 0 } : null;
|
|
}
|
|
|
|
async function due(k, now) {
|
|
if (!k) return false;
|
|
const t = now || Date.now();
|
|
try { const r = await row(k); return !r || !r.seen || t - r.seen >= everyMs(); } catch (e) { console.error('login-ad clock read', e.message); return true; }
|
|
}
|
|
async function served(k, now) {
|
|
if (!k) return;
|
|
const t = now || Date.now();
|
|
if (!pool) { const r = mem.get(k) || { seen: 0, served: 0 }; r.served = t; mem.set(k, r); return; }
|
|
try { await table(); await pool.query('INSERT INTO login_ad_views (k, served_at) VALUES (?, ?) ON DUPLICATE KEY UPDATE served_at = VALUES(served_at)', [k, t]); }
|
|
catch (e) { console.error('login-ad clock serve', e.message); }
|
|
}
|
|
// -> { ok: true } or { ok: false, reason }
|
|
async function seen(k, dwellSec, now) {
|
|
if (!k) return { ok: false, reason: 'signed out' };
|
|
const t = now || Date.now();
|
|
const need = Math.max(0, (Number(dwellSec) || 10) - 2) * 1000;
|
|
let r = null; try { r = await row(k); } catch (e) { console.error('login-ad clock read', e.message); return { ok: false, reason: 'store' }; }
|
|
if (!r || !r.served || t - r.served > SERVE_WINDOW) return { ok: false, reason: 'not served' };
|
|
if (t - r.served < need) return { ok: false, reason: 'too soon' };
|
|
if (!pool) { r.seen = t; mem.set(k, r); return { ok: true }; }
|
|
try { await pool.query('UPDATE login_ad_views SET seen_at = ? WHERE k = ?', [t, k]); return { ok: true }; }
|
|
catch (e) { console.error('login-ad clock seen', e.message); return { ok: false, reason: 'store' }; }
|
|
}
|
|
async function forget(k) {
|
|
if (!k) return;
|
|
mem.delete(k);
|
|
if (pool) { try { await table(); await pool.query('DELETE FROM login_ad_views WHERE k = ?', [k]); } catch (e) { console.error('login-ad clock forget', e.message); } }
|
|
}
|
|
|
|
module.exports = { init, keyOf, due, served, seen, forget, everyMs };
|