tickets
All repositories: gitoria
3.4 KB
// login.js — the small bridge between ident's <ident-selector> and the tickets shell// (components/main.hl; ticket #7). Plain JS because hl:webex cannot listen to a custom DOM// event: `ident-login` (event.detail.code, the one-time code) goes into the hidden input// #identcode, whose `change` the shell handles (→ face identLogin, server-side exchange).// The host tells the selector whether this site is logged in: the shell keeps the// element's class at `in` / `out`, mirrored here into its `loggedIn` property// (= the `logged-in` attribute; false = reset to "choose ident").//// RUNS ONCE PER DOCUMENT (ticket #9, mission 012). hl:webex re-creates the shell's header// and its <script> elements whenever the login state flips (login, logout): the browser// then executes this file AGAIN, and the selector element is a NEW one. The old version// added one more `ident-login` listener per run, so after a logout ONE selection fired// two `change`s → two exchanges of the same one-time code → the second one failed// ("ident refused the login (400: unknown or already used code)") although the first// had logged the user in. Now: one guarded install, listeners on `document` (the event// bubbles and is composed), the CURRENT #selector looked up each time, and a code is// handed to the shell at most once.//// LOGIN BUTTON (ticket #10): just before the browser follows "Log in with ident", its// return URL gets `?next=<this page's path + query>`; /login/callback checks it// (same-origin path only) and sends the user back there.(() => {if (window.__ticketsLogin) { window.__ticketsLogin.sync(); return; }const selector = () => document.getElementById('selector');const sync = () => {const sel = selector();// not upgraded yet: a property set now would shadow the element's own accessorif (!sel || !window.customElements || !customElements.get('ident-selector')) return;const want = sel.classList.contains('in');if (sel.loggedIn !== want) sel.loggedIn = want;};// the class flips, and whole new selector elements arrive (hl:webex re-renders the header)new MutationObserver(sync).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['class'] });if (window.customElements) customElements.whenDefined('ident-selector').then(sync);const handed = new Set();document.addEventListener('ident-login', (e) => {const code = e.detail && e.detail.code;const input = document.getElementById('identcode');if (!input || !code || handed.has(code)) return; // a one-time code is exchanged oncehanded.add(code);input.value = code;input.dispatchEvent(new Event('change', { bubbles: true }));});// "Log in with ident": return to this page (the server accepts only a same-origin path)const withNext = (a) => {try {const u = new URL(a.href);const ret = new URL(u.searchParams.get('return'));const here = location.pathname + location.search;ret.search = '';if (here !== '/' && here.length <= 500) ret.searchParams.set('next', here);u.searchParams.set('return', ret.href);a.href = u.href;} catch (err) { /* keep the server's href: the login still works, it returns to / */ }};const onButton = (e) => {const a = e.target && e.target.closest && e.target.closest('#loginbutton');if (a) withNext(a);};for (const t of ['click', 'auxclick', 'contextmenu']) document.addEventListener(t, onButton, true);window.__ticketsLogin = { sync };})();
Branches
Latest commits
- d876d0b2|||PR README: changes land as PRsmre
- 3b858c91Log backup hard-link fixmre
- 7f6b37a0deploy.sh backup: tar --hard-dereference (hard links broke mpackdb sidecars on restore)mre
- e93711d9Log E30 livemre
- 59c02e4dMerge e30: preserve edited state note labels in Markdownmre
- 30970796Log E30 deploy GOmre
- 7c8e6d83Limit edited state note fix to Markdown renderingmre
- 910536d0Log E30 reviewmre
- 36984386Preserve state transitions when their notes are editedmre
- d75cb946Log E30 startmre
- 0bf3fefaMission 030: edited state note labelmre
- 691565c6Log neutral-ticket rule checkmre
- bc3bdecerecords: day38b live, #94 purgedmre
- f6c5aa0dMerge main (records)mre
- e23d42acconnect gate: wait for hydration before clicking Disconnectmre
- a5d45d00records: D38 cause, GOmre
- 19eeb938records: D38 gates, two day38b failuresmre
- f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
- 51645016Merge purge-94 (#94, identity rule)mre
- 94d6ca2arecords: D38 startedmre