diff --git a/public/admin.html b/public/admin.html index f186f54..ec1e608 100644 --- a/public/admin.html +++ b/public/admin.html @@ -270,6 +270,7 @@ + Public wall @@ -653,6 +654,6 @@ - + diff --git a/public/assets/admin.js b/public/assets/admin.js index 208e4e9..7c5aaa9 100644 --- a/public/assets/admin.js +++ b/public/assets/admin.js @@ -544,6 +544,14 @@ if (act === 'sponsor') { const v = await IAP.ask({ title: 'Sponsor for ' + (a.username ? '@' + a.username : a.email), text: 'Username, share code or member #. Blank = no sponsor (company). Re-points free referrals and future purchases; on-chain sponsorship never changes.', value: a.sponsorRef || '', ok: 'Save' }); if (v === null || v === undefined) return; body = { sponsorRef: v }; } if (act === 'wallet') { const v = await IAP.ask({ title: 'Main wallet for ' + a.email, text: 'Paste the 0x address that should be their main wallet (the one that paid, if a purchase came from an unlinked account). The member number is re-read from the chain. Blank = unlink.', value: a.address || '', ok: 'Swap' }); if (v === null || v === undefined) return; if (!await IAP.confirmBox('Swap the main wallet for ' + a.email + ' to ' + (v.trim() || 'nothing') + '?', { title: 'Sure?', ok: 'Swap it', cancel: 'Cancel' })) return; body = { address: v }; } if (act === 'credits') { const v = await IAP.ask({ title: 'Grant credits to ' + (a.username ? '@' + a.username : a.email), text: 'Whole number of earned-pool credits (1 credit = 1 cent of delivery). They can spend them on campaigns right away.', type: 'number', value: '', placeholder: '250', ok: 'Grant' }); if (!v) return; const note = await IAP.ask({ title: 'Reason (kept in the server log)', value: '', placeholder: 'e.g. refund for broken banner', ok: 'Grant' }); body = { grantCredits: v, note: note || '' }; } + // message the member (Marty 2026-11-12): lands in their member inbox AND emails them (opt-outs honoured by the mailer) + if (act === 'message') { + const who = a.username ? '@' + a.username : a.email; + const subject = await IAP.ask({ title: 'Message ' + who, text: 'Subject line. The message goes to their member inbox and is emailed to them (unless they unsubscribed from email).', value: '', placeholder: 'A quick note from Marty', ok: 'Next' }); if (!subject) return; + const text = await IAP.ask({ title: subject, text: 'Your message. Plain text; blank lines start new paragraphs.', type: 'textarea', value: '', ok: 'Send' }); if (!text || !text.trim()) return; + const r = await api('/api/admin/member/message', { email: a.email, subject, text }, 'POST'); + IAP.status('Sent to ' + who + "'s inbox" + (r.emailed ? ' and emailed.' : r.emailSkipped ? '. Email skipped: ' + r.emailSkipped + '.' : '.'), r.emailed ? 'ok' : 'warn'); return; + } if (act === 'delete') { if (a.memberId) { IAP.status('Registered members cannot be deleted; their position is on-chain.', 'bad'); return; } if (!await IAP.confirmBox('Delete the free account ' + a.email + '? Their sign-in, referrals link and credits go away. There is no undo.', { title: 'Delete account', ok: 'Delete', cancel: 'Keep it' })) return; diff --git a/server.js b/server.js index 5f01c98..c9ac453 100644 --- a/server.js +++ b/server.js @@ -3204,6 +3204,27 @@ const server = http.createServer(async (req, res) => { // -- link-farm scan (2026-10-30): last result + allowlist, run now (no Telegram), allow / unallow an email if (p === '/api/admin/spamscan' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, spamscan.view()); } if (p === '/api/admin/spamscan/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); await spamscan.run({ manual: true, quiet: true }); return json(res, 200, spamscan.view()); } + // admin -> one member: inbox message + email (Marty 2026-11-12: "no way to send them an inbox message that would email them as well") + if (p === '/api/admin/member/message' && req.method === 'POST') { + if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); + const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); const acct = e && await accounts.byEmail(e); + if (!acct) return json(res, 404, { error: 'No such member.' }); + const subject = String(b.subject || '').trim().slice(0, 150), text = String(b.text || '').trim().slice(0, 8000); + if (!subject || !text) return json(res, 400, { error: 'Subject and message are both needed.' }); + const escH = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); + const html = text.split(/\n{2,}/).map(par => '

' + escH(par).replace(/\n/g, '
') + '

').join(''); + await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [e], subject, html, 'broadcast'); + let emailed = false, emailSkipped = ''; + if (!mailer.hasKey()) emailSkipped = 'mail is not set up on this server'; + else { + const hello = acct.username ? 'Hi @' + acct.username + ',\n\n' : 'Hi,\n\n'; + const tail = '\n\nYou can reply from your member inbox: https://instantadpay.com/my\n\nMarty Bostick, InstantAdPay'; + try { emailed = (await mailer.send(e, subject, hello + text + tail, '
' + '

' + escH(hello.trim()) + '

' + html + '

You can reply from your member inbox: instantadpay.com/my

Marty Bostick, InstantAdPay

')) !== false; if (!emailed) emailSkipped = 'they unsubscribed from email'; } + catch (err) { emailSkipped = 'the mail service failed (' + String(err.message || err).slice(0, 80) + ')'; } + } + console.log('admin message', e.replace(/^(.).*(@.*)$/, '$1***$2'), 'inbox ok', emailed ? 'emailed' : 'email skipped: ' + emailSkipped); + return json(res, 200, { ok: true, inbox: true, emailed, emailSkipped }); + } if (p === '/api/admin/spamscan/allow' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); if (!e) return json(res, 400, { error: 'Which email?' });