gitoriaLog in with ident

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita75e0279a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemrea75e0279/components/main.hl

7.8 KB

  1. // components/main.hl — THE SHELL: the application header (brand, All tickets, Inbox with
  2. // its live count, and TOP RIGHT the login: ident's identity selector + "Log in with ident",
  3. // or who you are + Log out), the display-name prompt of a first login, and the slot every
  4. // page renders into. All CSS is in styles.hl.
  5. //
  6. // LOGIN (ticket #7, CONCEPT.md "Login via ident"; ident README "How apps use ident"):
  7. // * THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js. Choosing an
  8. // identity fires `ident-login` with a one-time code. hl:webex cannot listen to a custom DOM
  9. // event, so /login.js (plain JS) hands the code to the hidden input #identcode and fires its
  10. // `change` — the handler below sends it to the face `identLogin`, which exchanges it SERVER
  11. // SIDE and logs this session in. No reload: the face answers who you are and pushes
  12. // `signedIn` to this session's tabs (the pages show their forms).
  13. // * THE HOST TELLS THE SELECTOR: the element's class is `in` / `out` (a member); /login.js
  14. // mirrors it into the selector's `loggedIn` (the `logged-in` attribute). Log out → `out`
  15. // → the selector is reset.
  16. // * THE LOGIN BUTTON: a plain link to <ident>/login?key=&return=<TICKETS_PUBLIC_URL>/login/callback
  17. // (project.hl loginCallback). /login.js adds `?next=<this page>` to the return URL at the
  18. // click, so the user comes back to the page the login started from (ticket #10).
  19. // * /login.js RUNS AGAIN whenever this View flips between logged in / out (hl:webex
  20. // re-creates the header and the <script> elements; ticket #9): it installs itself once
  21. // per document and hands each one-time code to #identcode only once.
  22. // * FIRST LOGIN: no display name yet → the name prompt below; writing waits for it.
  23. import { inboxCountOf } from '../lib/tickets.hl'
  24. import { siteName } from '../project.hl'
  25. import { identKey, selectorScript, loginHref, infoOfSession, exchangeCode, ensureUser, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  26. import { randomBytes } from 'hl:crypto'
  27. slot = null
  28. session = null
  29. // the inbox is PERSONAL (ticket #20): the tickets assigned to this session's user in pending and review
  30. inbox = inboxCountOf(userOfSession(session))
  31. hasInbox = inbox > 0
  32. // who this session is: { name, named, creator } — never the identity id
  33. me = infoOfSession(session)
  34. loggedIn = me != null
  35. loggedOut = me == null
  36. needsName = me != null && !me.named
  37. myName = me != null && me.named ? me.name : 'you'
  38. selectorClass = me != null ? 'in' : 'out'
  39. selectorKey = identKey
  40. identScript = selectorScript
  41. buttonHref = loginHref
  42. loginError = ''
  43. hasLoginError = false
  44. nameDraft = ''
  45. nameError = ''
  46. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network;
  47. // the shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  48. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  49. // write only when it changed. (An `img` error or a socket event would race the hydration and be missed.)
  50. offline = false
  51. View {
  52. body {
  53. applicationHeader {
  54. a { class = "brand" href = "/" siteName }
  55. nav {
  56. a { id = "navall" href = "/" "All tickets" }
  57. a { id = "navinbox" href = "/inbox" "Inbox"
  58. if (hasInbox) { inboxBadge { id = "inboxcount" inbox } }
  59. }
  60. }
  61. userBox { id = "userbox"
  62. identSelector { id = "selector" key = selectorKey class = selectorClass }
  63. if (loggedIn) {
  64. a { id = "whoami" href = "/you" myName }
  65. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  66. }
  67. if (loggedOut) {
  68. a { id = "loginbutton" class = "button" href = buttonHref "Log in with ident" }
  69. }
  70. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  71. }
  72. }
  73. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  74. if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  75. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  76. if (needsName) {
  77. namePrompt {
  78. form { id = "nameform"
  79. on submit(e) {
  80. e.preventDefault()
  81. emit saveName(e)
  82. }
  83. label { "Welcome! Choose the display name others see as the author of what you write"
  84. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  85. }
  86. button { id = "namesave" type = "submit" "Save" }
  87. p { id = "nameerror" class = "message" nameError }
  88. }
  89. }
  90. }
  91. main { slot }
  92. script { src = identScript }
  93. script { src = "/login.js" }
  94. // ticket #12: <md-editor> around every Markdown textarea (a page without JS keeps the plain
  95. // textarea; the script defines the element once, a re-run by webex is a no-op)
  96. script { src = "/md-editor.js" }
  97. }
  98. }
  99. // ---- the session as the page sees it ------------------------------------------------------
  100. showMe = (info) => {
  101. loggedIn = true
  102. loggedOut = false
  103. needsName = !info.named
  104. myName = info.named ? info.name : 'you'
  105. selectorClass = 'in'
  106. loginError = ''
  107. hasLoginError = false
  108. }
  109. showOut = () => {
  110. loggedIn = false
  111. loggedOut = true
  112. needsName = false
  113. myName = 'you'
  114. selectorClass = 'out'
  115. inbox = 0
  116. hasInbox = false
  117. }
  118. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  119. on gotCode(e) {
  120. code = e.target.value
  121. e.target.value = ''
  122. if (code == null || code == '') { return null }
  123. r = emit server identLogin(code)
  124. if (r == null || r.error != null) {
  125. loginError = r != null ? r.error : 'the login failed'
  126. hasLoginError = true
  127. return null
  128. }
  129. showMe(r)
  130. emit refreshInbox()
  131. }
  132. on setNameDraft(v) { nameDraft = v }
  133. on netTick(e) {
  134. down = window.navigator.onLine == false
  135. if (down != offline) { offline = down }
  136. }
  137. on saveName(e) {
  138. r = emit server saveDisplayName(nameDraft)
  139. if (r == null || r.error != null) {
  140. nameError = r != null ? r.error : 'could not save the name'
  141. return null
  142. }
  143. nameError = ''
  144. showMe(r)
  145. }
  146. on doLogout(e) {
  147. emit server logOut()
  148. showOut()
  149. }
  150. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  151. on refreshInbox() {
  152. r = emit server myInboxCount()
  153. if (r != null && r.count != null) {
  154. inbox = r.count
  155. hasInbox = r.count > 0
  156. }
  157. }
  158. on client ticketCreated(row) { emit refreshInbox() }
  159. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  160. // this session's other tabs follow a login / name / logout
  161. on client signedIn(tag, info) {
  162. showMe(info)
  163. emit refreshInbox()
  164. }
  165. on client signedOut(tag) { showOut() }
  166. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  167. on server identLogin(code, session) {
  168. if (session == null) { return { error = 'no session — reload the page' } }
  169. x = exchangeCode(code)
  170. if (x.error != null) { return { error = x.error } }
  171. u = ensureUser(x.identity)
  172. if (u == null) { return { error = 'could not store the user' } }
  173. tag = randomBytes(16)
  174. session.user = { id = u.id }
  175. session.data.tag = tag
  176. info = userInfo(u)
  177. emit client signedIn(tag, info)
  178. return info
  179. }
  180. on server saveDisplayName(name, session) {
  181. u = userOfSession(session)
  182. if (u == null) { return { error = 'log in with ident first' } }
  183. r = setUserName(u.id, name)
  184. if (r.error != null) { return { error = r.error } }
  185. info = userInfo(r.user)
  186. emit client signedIn(session.data.tag, info)
  187. return info
  188. }
  189. on server myInboxCount(session) {
  190. return { count = inboxCountOf(userOfSession(session)) }
  191. }
  192. on server logOut(session) {
  193. if (session == null) { return { error = 'no session' } }
  194. // the tag stays (the push may fan out after this face returns); the next login replaces it
  195. emit client signedOut(session.data.tag)
  196. session.user = null
  197. return { ok = true }
  198. }

Branches

Latest commits

  • a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemre
  • e9d5c618mission 010 (code order) 2/4: one lib/ file per topic — store.hl split into projects / tickets (+ relations) / events / tickets-helpers, util.hl shared helpers (env, storage dir, URLs, sorts, Vienna time), the function routes out of project.hl into lib/api.hl (thin; auth/filters/Accept in api-helpers.hl), invite + member-removal logic out of the faces/routes into invites.hl / tickets.hl; project.hl is the map. /login/callback gets req + the session store by reference. gate 249/0, connect 60/0, real-data reads identicalmre
  • 97e269b5mission 010 (code order) 1/4: .hl files out of the root — lib/ (store, users, connections, invites, migrate, markdown, mdview, import = ticketfile, util = localtime, jsoncheck, api-helpers = api), tools/import.hl, components/styles.hl; import paths only. gate 249/0, connect 60/0, real-data reads identicalmre
  • 38f9d10ftickets: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gate 249/0, connect 60/0mre
  • d3db6139tickets: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 249/0, connect 60/0mre
  • bce182e3tickets: Hybriel master 7eea0d32 (#126 memory, #48 lambda copies its argument); migrate.hl lambdas take &logmre
  • 4137be0fantcolony#40: mission references point to the moved missionsmre
  • 9bfba36aantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • c7bd2645tickets: Hybriel master 73267707 (#122 fixed); compactNow workaround removed (#110 covered)mre
  • 2ab91ee9tickets: gate checks rows appear once (session sync); re-vendor to ff51cf46 stopped on hybriel#122, stays 837fe120mre
  • e01c2b1dtickets#24: installable app (manifest, service worker, offline list), own icon; gate waits for the hello's pongmre
  • 752fbb7fdeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • 38bdd5e4deploy.sh: never send .git or .gitignore to Byrodinmre
  • f12fa1bcState of 2026-09-27, before the move to gitoriamre