gitoria
All repositories: gitoria
3.0 KB
// login.js — the small bridge between ident's <ident-selector> and gitoria's shell (components/main.hl;// gitoria#14, the same as tickets' login.js). Plain JS because hl:web 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 gitoriaLogin, server-side exchange). The shell keeps the selector element's class// at `in` / `out`; it is mirrored here into the selector's `loggedIn` (false = back to "choose ident").// ident answers the selector only for a REGISTERED origin — the main address and (the wildcard origin) every repo address.// BACK TO THE PAGE: the "Log in with ident" click gets `?next=<this page>` in its return URL — a path on the main// address, the full URL on a repo address (project.hl safeNext checks both). At the click, so it is the page the// address bar shows after any hl:web navigation.// RUNS ONCE PER DOCUMENT: hl:web re-creates the header and its <script>s when the login state flips, the// selector element is then a NEW one; listeners sit on `document`, the CURRENT #selector is looked up each// time, and a one-time code is handed to the shell at most once.(() => {if (window.__gitoriaLogin) { window.__gitoriaLogin.sync(); return; }const sync = () => {const sel = document.getElementById('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;};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 }));});const withNext = (a) => {try {const u = new URL(a.href);const ret = new URL(u.searchParams.get('return'));const main = ret.host === location.host;const here = main ? location.pathname + location.search : location.href;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.__gitoriaLogin = { sync };})();
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 4a3f557eImport layouts theme ebd00b6 for W61 (startup blocked)mre
- 53ca42b2log: W60 merged, W61 W62 startedmre
- 80870a33mission W61: style passmre
- 560fd208Merge W60: helpers, bound forms, login in topics, two form fixes (gitoria#28 #32 #33)mre
- ac5ba6a4log: W60, #25 measuredmre
- 220f6342W60: record corrected form proof, full AE and remaining gapsmre
- 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
- ae373cfdgitoria#28: keep each reply draft in its thread componentmre
- eeeebd5agitoria: insert a newly created organization oncemre
- 34d2d5cagitoria: clear the bound public-key textarea after creationmre
- 119e54c0W60: restore conductor-owned tracking filesmre
- 24b479e7W60: record final gates, Chrome failures and AE evidencemre
- 5e11184cW60: record partial validation, framework gaps and cleanupmre
- 20fe13fagitoria#33: centralize login and tickets connection statemre
- 859754c0gitoria#29: retain the offline note and record the framework gapmre
- d140bc04gitoria#30: reproduce the upsert ordering constraintmre
- 6960e8f8gitoria#28: keep form values in bound component membersmre
- 0db27200gitoria#32: share character checks and environment lookupmre
- 452f6a1amission W60: logic clean-upsmre
- 1448c899log: cleanup, #49 GPTBot, tracker mentions on #36mre