ident
All repositories: gitoria
3.1 KB
// lib/mail.hl — THE MAILER. One hl:smtp Mailer, configured from `.env` beside project.hl// (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_FROM; the real environment// outranks the file). A send is non-blocking: the SMTP conversation runs on the// mailer's thread and its outcome arrives on the event loop (logged below).//// IDENT_MAIL_SINK names a file that receives the mail INSTEAD of the SMTP server: one// line `<address> <code>` is APPENDED per code. The dev server and the gate use it, so// no real mail is sent until SMTP is configured for mail.byrod.in (see README).//// Handlers belong to instances: project.hl constructs this file once (`mail = new Mail()`).import { Mailer } from 'hl:smtp'import { env } from 'hl:proc'import { writeFile, readFile, exists } from 'hl:fs'static NL = ''static setting = (name, fallback) => { return env(name) != null && env(name) != '' ? env(name) : fallback }// An unconfigured dev setup gets the placeholder host 127.0.0.1 (the Mailer must exist:// `mailer.deliver()` and the `on mailer.…` handlers below); with the sink set nothing is ever// sent through it. SMTP_FROM's default is a real sender, not a placeholder — kept (mission 035).static smtpHost = setting('SMTP_HOST', null)static mailer = new Mailer(smtpHost != null ? smtpHost : '127.0.0.1', toNumber(setting('SMTP_PORT', '587')), {user = setting('SMTP_USER', null)pass = setting('SMTP_PASSWORD', null)sender = setting('SMTP_FROM', '[email protected]')})static sink = env('IDENT_MAIL_SINK') != null && env('IDENT_MAIL_SINK') != '' ? env('IDENT_MAIL_SINK') : nullstatic sendCode = (email, code) => {if (sink != null) {let before = exists(sink) ? readFile(sink) : ''writeFile(sink, before + email + ' ' + code + NL)return 0}if (smtpHost == null) {console.warn('mail: NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')return 0}return mailer.send({to = emailsubject = 'Your ident login code: ' + codetext = 'Hi,your one-time login code for worldapi is ' + code + 'It is valid for 10 minutes and works once. If you did not ask for it, ignore this mail.'})}// AN INVITATION MAIL (ident#22). With the sink set, the line `<address> <link>` goes to// `<sink>.invites` (a second file: the code reader of the gates keeps its own format).static sendInvite = (email, link, appName, project, role, days) => {if (sink != null) {let f = sink + '.invites'let before = exists(f) ? readFile(f) : ''writeFile(f, before + email + ' ' + link + NL)return 0}if (smtpHost == null) {console.warn('mail: invitation NOT SENT to ' + email + ' — neither IDENT_MAIL_SINK nor SMTP_HOST is set')return 0}return mailer.send({to = emailsubject = 'You are invited to ' + project + ' (' + appName + ')'text = 'Hi,you are invited to ' + project + ' in ' + appName + ' (role: ' + role + ').Open this link to join with ident:' + link + 'The link works for ' + days + ' days. If you were not expecting it, ignore this mail.'})}mailer.deliver()on mailer.sent(r) { console.log('mail: sent', r.id, r.to, r.message) }on mailer.failed(r) { console.warn('mail: FAILED', r.id, r.to, r.stage, r.code, r.message) }
Branches
- mainmain branch
Latest commits
- d2e7f91bident mission 009 (2/4): one lib file per topic (login, accounts, identities, apps, invites, selector, notify + helpers, util), function routes as thin wrappers in lib/api.hl, project.hl = the map; same outputmre
- 91017164ident mission 009 (1/4): file moves — the root .hl files into lib/ (api.hl → lib/api-helpers.hl), styles.hl → components/styles.hl; imports adjusted, no other changemre
- f8bdcbc2ident: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); all gates greenmre
- ff78726cident: Hybriel master 190aa11d (fc838894 GC correctness, #127, #126 closure scopes); gates all greenmre
- a3a7d21aident: Hybriel master 8efba065 (#126 GC by bytes, #48 lambda params copy); session-writing lambdas take &sessionmre
- 98226b41antcolony#40: mission references point to the moved missionsmre
- ff805b9aantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
- 51a7bcdfident: Hybriel master 73267707 (#122); /code uses the new page() signature; pending address passed as parameter; once-checksmre
- 836f644fident#24: installable app (manifest, service worker, data-free offline /start), own iconmre
- 8bebbbf2deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- cc063ea2deploy.sh: never send .git or .gitignore to Byrodinmre
- 81b15b7bState of 2026-09-27, before the move to gitoriamre