gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit109cfc5c109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre109cfc5c/components/main.hl

8.8 KB

  1. // components/main.hl — THE SHELL (gitoria#23): the WorldAPI theme's header and content-first shell (theme/shell/*, copied from
  2. // layouts.worldapi.org — never edited here, the way tracker.worldapi.org wears it) around the slot every page renders into, plus
  3. // the display-name prompt of a first login. All CSS is in styles.hl (the shell files carry their own Style).
  4. // THE HEADER: phone — ☰ (the sidebar overlay with the main menu) · brand · the user icon far right (its dropdown: your name,
  5. // Access tokens, SSH keys, Log out); signed out the ident icon stands there, its dropdown holds ident's selector and "Log in with
  6. // ident". From 60rem: brand · main menu · user icon; signed out the selector and the login button stand in the header themselves.
  7. // The main menu is the app's top level, on the main address: Repositories. The repo's own tabs stay in the repo head of the repo layout level (repo.hl).
  8. // THE SELECTOR (gitoria#14): `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in tickets.
  9. // Choosing an identity fires `ident-login` (one-time code); /login.js hands it to the hidden input
  10. // #identcode, whose `change` goes to the face gitoriaLogin (server-side exchange, no reload). The element's
  11. // class is `in` / `out`; /login.js mirrors it into the selector's `loggedIn`. ident only answers a REGISTERED
  12. // origin (the main address), so on a repo address (the request's host, `host = null`, hybriel#74) the selector
  13. // carries the class `onrepo` and styles.hl hides it — the button stays there.
  14. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl
  15. // loginCallback); /login.js adds `?next=<this page>` at the click so the login returns here.
  16. // FIRST LOGIN: no display name yet → the name prompt; creating a repo waits for it.
  17. import { siteName } from '../project.hl'
  18. import { slugOfHost, publicUrl } from '../lib/util.hl'
  19. import { identKey, selectorScript, loginHref, infoOfSession, userOfLoginCode, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  20. import { randomBytes } from 'hl:crypto'
  21. import AppHeader from '../theme/shell/app-header.hl'
  22. import MainMenu from '../theme/shell/main-menu.hl'
  23. import UserMenu from '../theme/shell/user-menu.hl'
  24. import Sidebar from '../theme/shell/app-sidebar.hl'
  25. import ContentFirst from '../theme/shell/content-first.hl'
  26. // the main menu: the header from 60rem, the phone's sidebar below — one list (every repo address links back to the main one)
  27. // `current = true` STAYS (hybriel#197 checked, mission 010): the route marker needs the item href to be the page path, but this item links to the MAIN address (absolute) and every page of the app (/code, /pulls …) lies under it, so the route cannot tell; it is marked on all
  28. static menu = [
  29. { label = 'Repositories' href = publicUrl + '/' current = true }
  30. ]
  31. slot = null
  32. session = null
  33. host = null
  34. me = infoOfSession(session)
  35. loggedIn = me != null
  36. loggedOut = me == null
  37. needsName = me != null && !me.named
  38. myName = me != null && me.named ? me.name : 'you'
  39. buttonHref = loginHref
  40. onRepoHost = slugOfHost(host) != ''
  41. selectorClass = (me != null ? 'in' : 'out') + (onRepoHost ? ' onrepo' : '')
  42. tokensHref = publicUrl + '/#tokens'
  43. keysHref = publicUrl + '/#sshkeys'
  44. selectorKey = identKey
  45. identScript = selectorScript
  46. loginError = ''
  47. hasLoginError = false
  48. nameDraft = ''
  49. nameError = ''
  50. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the
  51. // shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  52. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  53. // write only when it changed.
  54. offline = false
  55. View {
  56. body {
  57. AppHeader { brand = siteName
  58. MainMenu { items = menu }
  59. if (loggedIn) {
  60. UserMenu {
  61. p { id = "whoami" class = "who" myName }
  62. a { id = "tokenslink" href = tokensHref "Access tokens" }
  63. a { id = "keyslink" href = keysHref "SSH keys" }
  64. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  65. }
  66. }
  67. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  68. // is hidden (class `in`), the selector element stays: /login.js mirrors its state (gitoria#14)
  69. identMenu { class = selectorClass
  70. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  71. // the ident icon (as tracker's): a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  72. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  73. path { class = "ident-d-side" d = "M5 22.6 L7.8 14.2 C15.1 14.2 19 16.6 19.6 18.4 C20.2 20.2 16.2 22.6 5 22.6 Z" }
  74. path { class = "ident-d" "fill-rule" = "evenodd" d = "M5 21 L7.8 12.6 C15.1 12.6 19 15 19.6 16.8 C20.2 18.6 16.2 21 5 21 Z M10.7 14.4 C13.6 14.4 15.4 15.3 15.6 16.8 C15.8 18.3 13.7 19.2 10 19.2 Z" }
  75. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  76. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  77. }
  78. }
  79. identPanel { id = "ident-panel" popover = "auto"
  80. identSelector { id = "selector" key = selectorKey class = selectorClass }
  81. if (loggedOut) {
  82. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  83. }
  84. }
  85. }
  86. }
  87. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  88. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  89. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  90. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  91. if (needsName) {
  92. namePrompt {
  93. form { id = "nameform"
  94. on submit(e) {
  95. e.preventDefault()
  96. emit saveName(e)
  97. }
  98. label { "Welcome! Choose the display name others see as the owner of your repositories"
  99. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  100. }
  101. button { id = "namesave" type = "submit" "Save" }
  102. p { id = "nameerror" class = "message" nameError }
  103. }
  104. }
  105. }
  106. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  107. // page — `Sidebar` + `main { ContentFirst { slot } }`, as tracker does: the page slot must start its own line (hybriel#130)
  108. Sidebar { desktop = "false" MainMenu { items = menu } }
  109. main {
  110. ContentFirst { slot }
  111. }
  112. script { src = identScript }
  113. script { src = "/login.js" }
  114. }
  115. }
  116. showMe = (info) => {
  117. loggedIn = true
  118. loggedOut = false
  119. needsName = !info.named
  120. myName = info.named ? info.name : 'you'
  121. selectorClass = onRepoHost ? 'in onrepo' : 'in'
  122. loginError = ''
  123. hasLoginError = false
  124. }
  125. showOut = () => {
  126. loggedIn = false
  127. loggedOut = true
  128. needsName = false
  129. myName = 'you'
  130. selectorClass = onRepoHost ? 'out onrepo' : 'out'
  131. }
  132. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  133. on gotCode(e) {
  134. code = e.target.value
  135. e.target.value = ''
  136. if (code == null || code == '') { return null }
  137. r = emit server gitoriaLogin(code)
  138. if (r == null || r.error != null) {
  139. loginError = r != null ? r.error : 'the login failed'
  140. hasLoginError = true
  141. return null
  142. }
  143. showMe(r)
  144. }
  145. on client gitoriaSignedIn(tag, info) { showMe(info) }
  146. on client gitoriaSignedOut(tag) { showOut() }
  147. on setNameDraft(v) { nameDraft = v }
  148. on netTick(e) {
  149. down = window.navigator.onLine == false
  150. if (down != offline) { offline = down }
  151. }
  152. on saveName(e) {
  153. r = emit server gitoriaSaveName(nameDraft)
  154. if (r == null || r.error != null) {
  155. nameError = r != null ? r.error : 'could not save the name'
  156. return null
  157. }
  158. nameError = ''
  159. showMe(r)
  160. }
  161. on doLogout(e) {
  162. emit server gitoriaLogOut()
  163. showOut()
  164. }
  165. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  166. on server gitoriaLogin(code, session) {
  167. if (session == null) { return { error = 'no session — reload the page' } }
  168. x = userOfLoginCode(code)
  169. if (x.error != null) { return { error = x.error } }
  170. tag = randomBytes(16)
  171. session.user = { id = x.user.id }
  172. session.data.tag = tag
  173. info = userInfo(x.user)
  174. emit client gitoriaSignedIn(tag, info)
  175. return info
  176. }
  177. on server gitoriaSaveName(name, session) {
  178. u = userOfSession(session)
  179. if (u == null) { return { error = 'log in with ident first' } }
  180. r = setUserName(u.id, name)
  181. if (r.error != null) { return { error = r.error } }
  182. info = userInfo(r.user)
  183. emit client gitoriaSignedIn(session.data.tag, info)
  184. return info
  185. }
  186. on server gitoriaLogOut(session) {
  187. if (session == null) { return { error = 'no session' } }
  188. emit client gitoriaSignedOut(session.data.tag)
  189. session.user = null
  190. return { ok = true }
  191. }

Branches

Latest commits

  • 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
  • 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
  • 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
  • 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
  • d9e977f0reports/MG-mobile.md, LOGMG
  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre
  • c6364cedgitoria B1: compact Markdown blocks (one kind flag per block/span, empty and false fields omitted); same rendered HTML, page values -67%mre
  • cd99d2feWIP gitoria#22: always render the repo level's slot (missing-repo boot hang), pages render nothing without a repo; hydration diagnosis in reports/G2-hydrate.mdmre
  • e5404b9breport: commit idsmre
  • 63cfa21ereports/G2-repotabs.mdmre
  • 9b0516fdgitoria#22: mark the tab underline functional (check-theme), chain E2E: serve/measure split, bring the lisbeth tab to frontmre
  • 19bc1df8gitoria#22: all repo pages under ONE layout level (components/repo.hl, hl:web D-CHAIN): a tab click replaces only the page in the slot; head and tab nav stay the same DOM nodesmre
  • 40658417tests/browser.mjs: wait for the page to be live (hydrated) before clicking Merge — a click on the server-rendered button before the client mounted was lost (flaky 'Clashing change' under load)mre