gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit73f4f97d73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre73f4f97d/components/main.hl

5.8 KB

  1. // components/main.hl — THE SHELL: the application header and the slot the page renders
  2. // into. All CSS is in components/styles.hl.
  3. import { siteName } from '../project.hl'
  4. import { accountOfSession, signOutEverywhere } from '../lib/accounts.hl'
  5. import AppHeader from '../theme/shell/app-header.hl'
  6. import MainMenu from '../theme/shell/main-menu.hl'
  7. import UserMenu from '../theme/shell/user-menu.hl'
  8. import Sidebar from '../theme/shell/app-sidebar.hl'
  9. import ContentFirst from '../theme/shell/content-first.hl'
  10. slot = null
  11. // OFFLINE (mission 046): true while the shell's probe cannot reach ident (the note under the header says so)
  12. noNetwork = false
  13. // the main menu marks the current page from the route (hybriel#197, in the server's HTML too): `route = null` is the declaration,
  14. // MainMenu reads {path, params, pattern} itself — no `current` is passed
  15. route = null
  16. session = null
  17. shellEmail = accountOfSession(&session) != null ? accountOfSession(&session).email : ''
  18. shellIn = shellEmail != ''
  19. // the main menu: the header from 60rem, the phone's sidebar below — one list (signed in only: every page needs the account)
  20. static menu = [ { label = 'Identities' href = '/' } { label = 'Inbox' href = '/inbox' } { label = 'Apps' href = '/apps' } { label = 'Access' href = '/access' } { label = 'Docs' href = '/docs' } ]
  21. Style {
  22. inboxBell { display = 'block' flex = 'none'
  23. a { display = 'flex' alignItems = 'center' justifyContent = 'center' width = 'var(--layout-tap)' height = 'var(--layout-tap)' color = 'var(--color-text)'
  24. hover { color = 'var(--color-accent)' textDecoration = 'none' }
  25. svg { width = '1.5rem' height = '1.5rem' }
  26. }
  27. }
  28. }
  29. // THE SHELL (mission 012, phone first on the WorldAPI theme): ContentFirst for every page — ident has no list/detail
  30. // structure; a sign-in page is just the centred column without a sidebar. Signed in: theme AppHeader (brand · main menu ·
  31. // user menu) + the phone's Sidebar (☰ → the main menu). Signed out: the brand only (the page is the sign-in).
  32. View {
  33. body {
  34. AppHeader { brand = siteName
  35. if (shellIn) { MainMenu { items = menu } }
  36. // the inbox shortcut of the approved screens (ident#27 mockups showed a coloured bell emoji; he asked for our monochrome icon style):
  37. // the same outline as the header's other icons (24 grid, currentColor, 1.8 stroke, round caps)
  38. if (shellIn) {
  39. inboxBell {
  40. a { class = "inboxlink" href = "/inbox" title = "Inbox" 'aria-label' = "Inbox"
  41. svg { viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" 'stroke-width' = "1.8" 'stroke-linecap' = "round" 'stroke-linejoin' = "round" 'aria-hidden' = "true"
  42. path { d = "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }
  43. path { d = "M10.3 21a1.94 1.94 0 0 0 3.4 0" }
  44. }
  45. }
  46. }
  47. }
  48. if (shellIn) {
  49. UserMenu {
  50. p { id = "whoami" class = "who" shellEmail }
  51. button { id = "menusignout" type = "button" "Sign out" on click(e) { emit shellSignOut(e) } }
  52. button { id = "menusignoutall" type = "button" "Sign out everywhere" on click(e) { emit shellSignOutAll(e) } }
  53. }
  54. }
  55. }
  56. if (noNetwork) { offlineNote { id = "offline" "Offline — ident needs the network to sign in and to save" } }
  57. // THE NETWORK PROBE: a CSS animation (components/styles.hl `ident-net-probe`) starts half a second
  58. // after the page is up and repeats every 20 s; each start and repeat asks /api/online.
  59. // A View has no "mounted" event, and a probe that fired before the page is hydrated
  60. // would be lost, so the delayed animation is the trigger. No JavaScript of ours.
  61. netProbe { on animationstart(e) { emit probe(e) } on animationiteration(e) { emit probe(e) } }
  62. if (shellIn) { Sidebar { desktop = "false" MainMenu { items = menu } } }
  63. // `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  64. main {
  65. ContentFirst { slot }
  66. }
  67. script { src = "/avatar.js" }
  68. }
  69. }
  70. // 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 reload
  71. on shellSession(email) {
  72. shellEmail = email
  73. shellIn = email != ''
  74. }
  75. // the user menu's Sign out: the session forgets the account, the page reloads into the sign-in
  76. on shellSignOut(e) {
  77. r = emit server shellSignOutNow()
  78. window.location.assign('/')
  79. }
  80. on server shellSignOutNow(session) {
  81. if (session != null) { session.user = null }
  82. return true
  83. }
  84. // 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
  85. // (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in form
  86. on shellSignOutAll(e) {
  87. if (!confirm('Sign out of ident on every device?')) { return null }
  88. r = emit server shellSignOutAllNow()
  89. if (r != null && r.error == null) { window.location.assign('/') }
  90. }
  91. on server shellSignOutAllNow(session) {
  92. let me = accountOfSession(&session)
  93. if (me == null) { return { error = 'you are not signed in' } }
  94. emit client signedOutAll(me.id)
  95. session.user = null
  96. return signOutEverywhere(me.id)
  97. }
  98. // the probe: no answer (or not ident's 204) = offline; the next repeat clears it again.
  99. // On `/start` (the installed app's start page, start.hl) an answer means: go on to `/`.
  100. on probe(e) {
  101. r = window.__hlAttempt(() => { return fetch('/api/online', { cache = 'no-store' }) })
  102. noNetwork = !r.ok || r.value.status != 204
  103. if (!noNetwork && window.location.pathname == '/start') { window.location.replace('/') }
  104. }
  105. // "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes
  106. // this to every open page of the account (project.hl audience), which reloads into the
  107. // signed-out state at once — no click needed.
  108. on client signedOutAll(accountId) {
  109. // the page that asked for it (the user menu's own sign-out, above) has already left for the sign-in: nothing to reload there
  110. if (shellEmail != '') { window.location.reload() }
  111. }

Branches

Latest commits

  • 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
  • d8be66ebident: report and log line for the widget cache and frame height changemre
  • 2068f61aident#31: browsers revalidate the widget scripts on every load; the sign-in frame is exactly as tall as the current step (the frame page reports its height, selector.js accepts it from ident only)mre