ident
All repositories: gitoria
5.8 KB
// components/main.hl — THE SHELL: the application header and the slot the page renders// into. All CSS is in components/styles.hl.import { siteName } from '../project.hl'import { accountOfSession, signOutEverywhere } from '../lib/accounts.hl'import AppHeader from '../theme/shell/app-header.hl'import MainMenu from '../theme/shell/main-menu.hl'import UserMenu from '../theme/shell/user-menu.hl'import Sidebar from '../theme/shell/app-sidebar.hl'import ContentFirst from '../theme/shell/content-first.hl'slot = null// OFFLINE (mission 046): true while the shell's probe cannot reach ident (the note under the header says so)noNetwork = false// the main menu marks the current page from the route (hybriel#197, in the server's HTML too): `route = null` is the declaration,// MainMenu reads {path, params, pattern} itself — no `current` is passedroute = nullsession = nullshellEmail = accountOfSession(&session) != null ? accountOfSession(&session).email : ''shellIn = shellEmail != ''// the main menu: the header from 60rem, the phone's sidebar below — one list (signed in only: every page needs the account)static menu = [ { label = 'Identities' href = '/' } { label = 'Inbox' href = '/inbox' } { label = 'Apps' href = '/apps' } { label = 'Access' href = '/access' } { label = 'Docs' href = '/docs' } ]Style {inboxBell { display = 'block' flex = 'none'a { display = 'flex' alignItems = 'center' justifyContent = 'center' width = 'var(--layout-tap)' height = 'var(--layout-tap)' color = 'var(--color-text)'hover { color = 'var(--color-accent)' textDecoration = 'none' }svg { width = '1.5rem' height = '1.5rem' }}}}// THE SHELL (mission 012, phone first on the WorldAPI theme): ContentFirst for every page — ident has no list/detail// structure; a sign-in page is just the centred column without a sidebar. Signed in: theme AppHeader (brand · main menu ·// user menu) + the phone's Sidebar (☰ → the main menu). Signed out: the brand only (the page is the sign-in).View {body {AppHeader { brand = siteNameif (shellIn) { MainMenu { items = menu } }// the inbox shortcut of the approved screens (ident#27 mockups showed a coloured bell emoji; he asked for our monochrome icon style):// the same outline as the header's other icons (24 grid, currentColor, 1.8 stroke, round caps)if (shellIn) {inboxBell {a { class = "inboxlink" href = "/inbox" title = "Inbox" 'aria-label' = "Inbox"svg { viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" 'stroke-width' = "1.8" 'stroke-linecap' = "round" 'stroke-linejoin' = "round" 'aria-hidden' = "true"path { d = "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }path { d = "M10.3 21a1.94 1.94 0 0 0 3.4 0" }}}}}if (shellIn) {UserMenu {p { id = "whoami" class = "who" shellEmail }button { id = "menusignout" type = "button" "Sign out" on click(e) { emit shellSignOut(e) } }button { id = "menusignoutall" type = "button" "Sign out everywhere" on click(e) { emit shellSignOutAll(e) } }}}}if (noNetwork) { offlineNote { id = "offline" "Offline — ident needs the network to sign in and to save" } }// THE NETWORK PROBE: a CSS animation (components/styles.hl `ident-net-probe`) starts half a second// after the page is up and repeats every 20 s; each start and repeat asks /api/online.// A View has no "mounted" event, and a probe that fired before the page is hydrated// would be lost, so the delayed animation is the trigger. No JavaScript of ours.netProbe { on animationstart(e) { emit probe(e) } on animationiteration(e) { emit probe(e) } }if (shellIn) { Sidebar { desktop = "false" MainMenu { items = menu } } }// `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)main {ContentFirst { slot }}script { src = "/avatar.js" }}}// a page's in-place sign-in (home.hl verify): its emit reaches this shell (hybriel#193), so the user menu follows at once, no reloadon shellSession(email) {shellEmail = emailshellIn = email != ''}// the user menu's Sign out: the session forgets the account, the page reloads into the sign-inon shellSignOut(e) {r = emit server shellSignOutNow()window.location.assign('/')}on server shellSignOutNow(session) {if (session != null) { session.user = null }return true}// the user menu's Sign out everywhere (the home page has no sign-out buttons of its own any more): every device is signed out// (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in formon shellSignOutAll(e) {if (!confirm('Sign out of ident on every device?')) { return null }r = emit server shellSignOutAllNow()if (r != null && r.error == null) { window.location.assign('/') }}on server shellSignOutAllNow(session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }emit client signedOutAll(me.id)session.user = nullreturn signOutEverywhere(me.id)}// the probe: no answer (or not ident's 204) = offline; the next repeat clears it again.// On `/start` (the installed app's start page, start.hl) an answer means: go on to `/`.on probe(e) {r = window.__hlAttempt(() => { return fetch('/api/online', { cache = 'no-store' }) })noNetwork = !r.ok || r.value.status != 204if (!noNetwork && window.location.pathname == '/start') { window.location.replace('/') }}// "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes// this to every open page of the account (project.hl audience), which reloads into the// signed-out state at once — no click needed.on client signedOutAll(accountId) {// the page that asked for it (the user menu's own sign-out, above) has already left for the sign-in: nothing to reload thereif (shellEmail != '') { window.location.reload() }}
Branches
Latest commits
- 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
- 23971fb7ident#49: media queries in the language's @media formmre
- 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
- aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
- ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
- dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
- d277633cident#27: README: identity access and the introspect endpointmre
- e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
- 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
- a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
- d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
- ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
- 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
- c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
- 80965c08ident#28: README says the deploy goes through the standbymre
- 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
- a544b261ident#28: README names the new vendored Hybrielmre
- 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
- 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre
- f5a55f8aident#11: apps can ask for nickname, firstname and lastname (fields list on /api/exchange, new POST /api/profile); empty fields come back null; gate checks, READMEmre