gitoriaLog in with ident

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain4f47843egate: ticket links use the tickets short URL (/<slug>/<n>, tickets#25)mremain/components/main.hl

5.7 KB

  1. // components/main.hl — THE SHELL: the application header (brand; top right the login: ident's
  2. // "Log in with ident" button, or who you are + Log out), the display-name prompt of a first login,
  3. // and the slot every page renders into. All CSS is in styles.hl.
  4. // THE SELECTOR (gitoria#14): `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in tickets.
  5. // Choosing an identity fires `ident-login` (one-time code); /login.js hands it to the hidden input
  6. // #identcode, whose `change` goes to the face gitoriaLogin (server-side exchange, no reload). The element's
  7. // class is `in` / `out`; /login.js mirrors it into the selector's `loggedIn`. ident only answers a REGISTERED
  8. // origin (the main address), so on a repo address (the request's host, `host = null`, hybriel#74) the selector
  9. // carries the class `onrepo` and styles.hl hides it — the button stays there.
  10. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl
  11. // loginCallback); /login.js adds `?next=<this page>` at the click so the login returns here.
  12. // FIRST LOGIN: no display name yet → the name prompt; creating a repo waits for it.
  13. import { siteName } from '../project.hl'
  14. import { slugOfHost } from '../lib/util.hl'
  15. import { identKey, selectorScript, loginHref, infoOfSession, userOfLoginCode, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  16. import { randomBytes } from 'hl:crypto'
  17. slot = null
  18. session = null
  19. host = null
  20. me = infoOfSession(session)
  21. loggedIn = me != null
  22. loggedOut = me == null
  23. needsName = me != null && !me.named
  24. myName = me != null && me.named ? me.name : 'you'
  25. buttonHref = loginHref
  26. onRepoHost = slugOfHost(host) != ''
  27. selectorClass = (me != null ? 'in' : 'out') + (onRepoHost ? ' onrepo' : '')
  28. selectorKey = identKey
  29. identScript = selectorScript
  30. loginError = ''
  31. hasLoginError = false
  32. nameDraft = ''
  33. nameError = ''
  34. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the
  35. // shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  36. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  37. // write only when it changed.
  38. offline = false
  39. View {
  40. body {
  41. applicationHeader {
  42. a { class = "brand" href = "/" siteName }
  43. userBox { id = "userbox"
  44. identSelector { id = "selector" key = selectorKey class = selectorClass }
  45. if (loggedIn) {
  46. span { id = "whoami" myName }
  47. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  48. }
  49. if (loggedOut) {
  50. a { id = "loginbutton" class = "button" href = buttonHref "Log in with ident" }
  51. }
  52. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  53. }
  54. }
  55. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  56. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  57. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  58. if (needsName) {
  59. namePrompt {
  60. form { id = "nameform"
  61. on submit(e) {
  62. e.preventDefault()
  63. emit saveName(e)
  64. }
  65. label { "Welcome! Choose the display name others see as the owner of your repositories"
  66. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  67. }
  68. button { id = "namesave" type = "submit" "Save" }
  69. p { id = "nameerror" class = "message" nameError }
  70. }
  71. }
  72. }
  73. main { slot }
  74. script { src = identScript }
  75. script { src = "/login.js" }
  76. }
  77. }
  78. showMe = (info) => {
  79. loggedIn = true
  80. loggedOut = false
  81. needsName = !info.named
  82. myName = info.named ? info.name : 'you'
  83. selectorClass = onRepoHost ? 'in onrepo' : 'in'
  84. loginError = ''
  85. hasLoginError = false
  86. }
  87. showOut = () => {
  88. loggedIn = false
  89. loggedOut = true
  90. needsName = false
  91. myName = 'you'
  92. selectorClass = onRepoHost ? 'out onrepo' : 'out'
  93. }
  94. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  95. on gotCode(e) {
  96. code = e.target.value
  97. e.target.value = ''
  98. if (code == null || code == '') { return null }
  99. r = emit server gitoriaLogin(code)
  100. if (r == null || r.error != null) {
  101. loginError = r != null ? r.error : 'the login failed'
  102. hasLoginError = true
  103. return null
  104. }
  105. showMe(r)
  106. }
  107. on client gitoriaSignedIn(tag, info) { showMe(info) }
  108. on client gitoriaSignedOut(tag) { showOut() }
  109. on setNameDraft(v) { nameDraft = v }
  110. on netTick(e) {
  111. down = window.navigator.onLine == false
  112. if (down != offline) { offline = down }
  113. }
  114. on saveName(e) {
  115. r = emit server gitoriaSaveName(nameDraft)
  116. if (r == null || r.error != null) {
  117. nameError = r != null ? r.error : 'could not save the name'
  118. return null
  119. }
  120. nameError = ''
  121. showMe(r)
  122. }
  123. on doLogout(e) {
  124. emit server gitoriaLogOut()
  125. showOut()
  126. }
  127. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  128. on server gitoriaLogin(code, session) {
  129. if (session == null) { return { error = 'no session — reload the page' } }
  130. x = userOfLoginCode(code)
  131. if (x.error != null) { return { error = x.error } }
  132. tag = randomBytes(16)
  133. session.user = { id = x.user.id }
  134. session.data.tag = tag
  135. info = userInfo(x.user)
  136. emit client gitoriaSignedIn(tag, info)
  137. return info
  138. }
  139. on server gitoriaSaveName(name, session) {
  140. u = userOfSession(session)
  141. if (u == null) { return { error = 'log in with ident first' } }
  142. r = setUserName(u.id, name)
  143. if (r.error != null) { return { error = r.error } }
  144. info = userInfo(r.user)
  145. emit client gitoriaSignedIn(session.data.tag, info)
  146. return info
  147. }
  148. on server gitoriaLogOut(session) {
  149. if (session == null) { return { error = 'no session' } }
  150. emit client gitoriaSignedOut(session.data.tag)
  151. session.user = null
  152. return { ok = true }
  153. }

Branches

Latest commits

  • 4f47843egate: ticket links use the tickets short URL (/<slug>/<n>, tickets#25)mre
  • 86605446mission 002 (code order) 4/4: README file map + import order + 'Same output' test + gate run with a tickets HEAD copy, STATUS (entry, lessons), LOG, report; tests/realdata-baseline.mjs + realdata-compare.py (a cleanup answers the same on live data: pages, modules, API, git over HTTPS and SSH, faces), tests/letcount.pymre
  • cc7bf7bamission 002 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (289 lets → plain declarations; 213 left: 125 reassigned, 88 loop-bound; no member/import/param clash). gates 200/0, 46/0, 44/0; real-data reads + writes identical (browser modules: var → const only)mre
  • 090a20c6mission 002 (code order) 2/4: one lib/ file per topic — git.hl split into git (calls, branches, init, temp folder) / homepage / code / pulls / releases (+ git-helpers: paths, ids, |||PR/|||RL markers); repos-helpers, tickets-helpers, transport-helpers; util.hl = localtime + env, storage dir, addresses, lists, text checks, one newest-first sort (was 3 copies); the function routes out of project.hl into lib/api.hl (thin; plumbing in api-helpers.hl), sshgate.hl folded into api.hl + sshkeys.hl keyLine + repos.hl mayPush; 'Make main' and the merge answer out of the faces (code.hl makeMain, pulls.hl pullsView), one login helper (users.hl userOfLoginCode); project.hl is the map. Session-writing routes get &req + &server.sessions. gates 200/0, 46/0, 44/0; real-data identical except /login/failed now shows the parked reason for a browser that already had a session (the old copy-of-req lost it)mre
  • 110c2799mission 002 (code order) 1/4: .hl files out of the root — lib/ (api, git, localtime, markdown, repos, sshgate, sshkeys, tickets, tokens, transport, users), components/styles.hl; jsoncheck.hl removed (imported nowhere); import paths only. gates 200/0, 46/0, 44/0; real-data reads + writes identicalmre
  • fdfb4b1bgitoria: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 200/0, 46/0, 44/0mre
  • 5b46ac84antcolony#40: LOG.md — missions 069/072 are antcolony missions (report paths on Byrodin)mre
  • 5602ff41gitoria: Hybriel master 190aa11d (fc838894 GC correctness, #127 mountKids by reference, #126, #48) — tracker README flat; gates 200/0, 46/0, 44/0mre
  • e85eaf01gitoria: 069 round 2 — hybriel 1a096ad3 not adopted (Markdown SSR still grows); browser gate waits for the server-side logout before restartmre
  • 09ce4f3fgitoria: mission 069 re-vendor hybriel 8efba065 stopped (big SSR pages grow + slow down); lambda audit clean; old vendor keptmre
  • 3dc43108antcolony#40: mission references point to the moved missionsmre
  • 8d9450fdantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 205d5fe4gitoria: Hybriel master ff51cf46; ssh keys/tokens no double rows (session sync); gates follow #20mre
  • 9b27cb26gitoria#21: installable app (manifest, service worker, offline start page), own iconmre
  • 68dcb603deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • e2deed6dgitoria#20: "Add code" only on the Code page of an empty repository, no collapsiblemre
  • 8bb97ffddeploy.sh: never send .git or .gitignore to Byrodinmre
  • fd981932State of 2026-09-27; bin/ no longer tracked (Hybriel commit is in README)mre
  • 4a2d7125initial commitmre