gitoriaLog in with ident

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2149e9022149e902notes mission 002 (4/4): code order — README file map + same-output test, STATUS, LOG, report; tests/letcount.py, tests/realdata-baseline.mjs, tests/realdata-compare.pymre2149e902/login.js

2.6 KB

  1. // login.js — the small bridge between ident's <ident-selector> and the notes shell (components/main.hl; the same
  2. // as gitoria's login.js). Plain JS because hl:web cannot listen to a custom DOM event: `ident-login`
  3. // (event.detail.code, the one-time code) goes into the hidden input #identcode, whose `change` the shell handles
  4. // (→ face notesLogin, server-side exchange). The shell keeps the selector element's class at `in` / `out`; it is
  5. // mirrored here into the selector's `loggedIn` (false = back to "choose ident").
  6. // BACK TO THE PAGE: the "Log in with ident" click gets `?next=<this page>` in its return URL (project.hl safePath).
  7. // RUNS ONCE PER DOCUMENT: hl:web re-creates the header and its <script>s when the login state flips, the
  8. // selector element is then a NEW one; listeners sit on `document`, the CURRENT #selector is looked up each
  9. // time, and a one-time code is handed to the shell at most once.
  10. (() => {
  11. if (window.__notesLogin) { window.__notesLogin.sync(); return; }
  12. const sync = () => {
  13. const sel = document.getElementById('selector');
  14. // not upgraded yet: a property set now would shadow the element's own accessor
  15. if (!sel || !window.customElements || !customElements.get('ident-selector')) return;
  16. const want = sel.classList.contains('in');
  17. if (sel.loggedIn !== want) sel.loggedIn = want;
  18. };
  19. new MutationObserver(sync).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['class'] });
  20. if (window.customElements) customElements.whenDefined('ident-selector').then(sync);
  21. const handed = new Set();
  22. document.addEventListener('ident-login', (e) => {
  23. const code = e.detail && e.detail.code;
  24. const input = document.getElementById('identcode');
  25. if (!input || !code || handed.has(code)) return; // a one-time code is exchanged once
  26. handed.add(code);
  27. input.value = code;
  28. input.dispatchEvent(new Event('change', { bubbles: true }));
  29. });
  30. const withNext = (a) => {
  31. try {
  32. const u = new URL(a.href);
  33. const ret = new URL(u.searchParams.get('return'));
  34. const here = location.pathname + location.search;
  35. ret.search = '';
  36. if (here !== '/' && here.length <= 500) ret.searchParams.set('next', here);
  37. u.searchParams.set('return', ret.href);
  38. a.href = u.href;
  39. } catch (err) { /* keep the server's href: the login still works, it returns to / */ }
  40. };
  41. const onButton = (e) => {
  42. const a = e.target && e.target.closest && e.target.closest('#loginbutton');
  43. if (a) withNext(a);
  44. };
  45. for (const t of ['click', 'auxclick', 'contextmenu']) document.addEventListener(t, onButton, true);
  46. window.__notesLogin = { sync };
  47. })();

Branches

Latest commits

  • 2149e902notes mission 002 (4/4): code order — README file map + same-output test, STATUS, LOG, report; tests/letcount.py, tests/realdata-baseline.mjs, tests/realdata-compare.pymre
  • 47db4fc1notes mission 002 (3/4): code order — let only where reassigned (58 dropped; 34 left: 19 reassigned, 15 loop-bound); gates 50/0 + 18/0, live-data run = step 2mre
  • 3f8cb383notes mission 002 (2/4): code order — topics, map, thin wrappers: lib/util.hl, lib/notes(-helpers).hl, lib/users.hl (+userOfLoginCode, tagOf), lib/api(-helpers).hl; project.hl = map; login routes take &req/&sessions (failed-login reason now kept); dead notes#1 functions removed; gates 50/0 + 18/0mre
  • 8cda5412notes mission 002 (1/4): code order — files moved: lib/notes.hl, lib/users.hl, lib/jsoncheck.hl, components/styles.hl (imports only); gates 50/0 + 18/0, live-data run identicalmre
  • 47dad68bnotes: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 50/0 + 18/0mre
  • a4a2b2aeantcolony#40: tracker missions moved too — references to them in missions/reports/LOG.md updatedmre
  • 3dea0ef2notes: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 50/0mre
  • e27c7d71notes: Hybriel master 8efba065 (#126 GC by bytes, #48 lambda params copy; audit: nothing to fix; gate 50/0)mre
  • 124613b6antcolony#40: mission references point to the moved missionsmre
  • 1ca2f34dantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 2bebebdanotes: Hybriel master ff51cf46 (re-vendor round)mre
  • 3eff126dnotes#3: installable app (manifest + own icon/favicon; notes' own sw.js kept)mre
  • 9883c540deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • eee693b8deploy.sh: never send .git or .gitignore to Byrodinmre
  • c8904061State of 2026-09-27, before the move to gitoriamre