Code box survives a board reload: the board hands back the member's started mission, a second Start reuses the live token, and submit accepts the code of any live token of theirs for that mission (ticket IAP-1027, phones that open the site in the board's own window)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
+14
-4
@@ -49,6 +49,14 @@ function issue(memberId, missionId, extra) {
|
||||
return rec;
|
||||
}
|
||||
function token(t) { const rec = store.read('tokens', {})[String(t || '')]; return rec && rec.exp > Date.now() ? rec : null; }
|
||||
// a member's live Code Hunt tokens (no kind), newest first; missionId narrows it to one mission. The board uses the
|
||||
// newest to bring the code box back after a reload, and start reuses it so a code already on screen keeps matching
|
||||
// (2026-11-24: on phones the site opened in the board's own window, the reload lost the box, and a second Start
|
||||
// issued a new token whose code no longer matched the one on screen)
|
||||
function live(memberId, missionId) {
|
||||
const all = store.read('tokens', {}), now = Date.now();
|
||||
return Object.keys(all).map(k => all[k]).filter(r => r && !r.kind && r.exp > now && r.memberId === Number(memberId) && (missionId === undefined || r.missionId === missionId)).sort((x, y) => y.iat - x.iat);
|
||||
}
|
||||
|
||||
// the proof: six characters from HMAC(secret, token); shown by the embed, typed by the hunter
|
||||
function codeFor(rec) { return h('code:' + rec.t + ':' + rec.memberId + ':' + rec.missionId).toString('hex').slice(0, 6).toUpperCase(); }
|
||||
@@ -75,11 +83,13 @@ function check(t, memberId, typed) {
|
||||
const rec = token(t); if (!rec) return { error: 'That mission timed out. Start it again from your board.' };
|
||||
if (rec.memberId !== Number(memberId)) return { error: 'That mission belongs to a different account.' };
|
||||
if (rec.kind) return { error: 'That is an Ad Detective case. Answer its question on your board.' };
|
||||
const want = codeFor(rec);
|
||||
const got = String(typed || '').trim().toUpperCase();
|
||||
if (got.length !== 6) return { error: 'Codes are 6 characters and you typed ' + got.length + '. Look at the site again: the code sits in six boxes, and a tap on it copies all six.' };
|
||||
if (got !== want) return { error: 'That is not the code. It is on the site, and it is yours alone.' };
|
||||
return { ok: true, rec };
|
||||
if (got === codeFor(rec)) return { ok: true, rec };
|
||||
// pressed Start more than once: the code on screen may belong to another live token of theirs for this same mission
|
||||
const other = live(rec.memberId, rec.missionId).find(r => r.t !== rec.t && codeFor(r) === got);
|
||||
if (other) return { ok: true, rec: other };
|
||||
return { error: 'That is not the code. It is on the site, and it is yours alone.' };
|
||||
}
|
||||
|
||||
module.exports = { list, get, save, remove, forMember, issue, token, codeForEmbed, check, ctDay, onVisit: null };
|
||||
module.exports = { list, get, save, remove, forMember, issue, token, live, codeForEmbed, check, ctDay, onVisit: null };
|
||||
|
||||
Reference in New Issue
Block a user