gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit477d7bdc477d7bdcMerge branch 'p50'mre477d7bdc/components/tokens.hl

5.2 KB

  1. // components/tokens.hl — ACCESS TOKENS (gitoria#7): what a developer's git uses as the PASSWORD to push over HTTPS
  2. // (transport.hl). On the main address, for a logged-in user: make a named token — its secret is shown ONCE, right
  3. // after it is made (only its hash is stored) — list the own tokens, remove one. Composed into list.hl (`#tokens`).
  4. import { infoOfSession, userOfSession, userIdOfSession } from '../lib/users.hl'
  5. import { tokenRows, createToken, revokeToken } from '../lib/tokens.hl'
  6. session = null
  7. me = infoOfSession(session)
  8. shown = me != null
  9. myUserId = userIdOfSession(session)
  10. tokens = myUserId != null ? tokenRows(myUserId) : []
  11. showHead = shown
  12. showForm = shown
  13. showSecret = false
  14. showNone = shown && tokens.length == 0
  15. tokenError = ''
  16. newSecret = ''
  17. hasSecret = false
  18. tokenName = ''
  19. View {
  20. accessTokens { id = "tokens"
  21. if (showHead) { h2 { "Access tokens" } }
  22. if (showHead) { p { class = "muted" "To push with git over HTTPS, use a token as the password (any user name). Reading a repository needs no token." } }
  23. if (showForm) {
  24. form { id = "tokenform"
  25. on submit(e) {
  26. e.preventDefault()
  27. emit makeToken(e)
  28. }
  29. label { "Name (for example the computer it is for)"
  30. input { id = "tokenname" name = "tokenname" required = "required" maxlength = "60" autocomplete = "off" value = tokenName on input(e) { emit setTokenName(e.target.value) } }
  31. }
  32. button { id = "tokensave" type = "submit" "Make token" }
  33. p { id = "tokenerror" tokenError }
  34. }
  35. }
  36. if (showSecret) { p { id = "tokennotice" "Copy your token now — it is not shown again:" } }
  37. if (showSecret) { pre { id = "tokensecret" newSecret } }
  38. if (showNone) { p { id = "notokens" class = "muted" "You have no tokens yet." } }
  39. ol { id = "tokenlist"
  40. for (t of tokens) {
  41. li {
  42. span { t.name }
  43. time { t.created }
  44. // Existing theme and test-hook classes have no component Style rule.
  45. button { class = "quiet removetoken" type = "button" value = t.@id "Remove" on click(e) { emit removeToken(e.target.value) } }
  46. }
  47. }
  48. }
  49. }
  50. }
  51. // one `if` per element, none inside another (a nested `if` broke the client's repaint on logout)
  52. on setTokenName(v) { tokenName = v }
  53. on makeToken(e) {
  54. r = emit server gitoriaMakeToken(tokenName)
  55. if (r == null || r.error != null) {
  56. tokenError = r != null ? r.error : 'could not make the token'
  57. return null
  58. }
  59. tokenError = ''
  60. tokenName = ''
  61. newSecret = r.token
  62. hasSecret = true
  63. // the face's answer can bring `tokens` fresh from the server already (hl:web ships a member derived from
  64. // `session` in the ack's sync, hybriel 64527baa) — so the new row is put on top ONCE, never twice
  65. tokens.remove(r.row.@id)
  66. tokens = [r.row, for (x of tokens) { x }]
  67. showHead = shown
  68. showForm = shown
  69. showSecret = shown && hasSecret
  70. showNone = shown && tokens.length == 0
  71. }
  72. on removeToken(id) {
  73. r = emit server gitoriaRemoveToken(id)
  74. if (r == null || r.error != null) {
  75. tokenError = r != null ? r.error : 'could not remove the token'
  76. return null
  77. }
  78. tokenError = ''
  79. tokens.remove(id)
  80. showHead = shown
  81. showForm = shown
  82. showSecret = shown && hasSecret
  83. showNone = shown && tokens.length == 0
  84. }
  85. // a login / logout (the shell's faces push them) shows or hides the section
  86. on client gitoriaSignedIn(tag, info) {
  87. shown = true
  88. hasSecret = false
  89. showHead = shown
  90. showForm = shown
  91. showSecret = shown && hasSecret
  92. showNone = shown && tokens.length == 0
  93. }
  94. on client gitoriaSignedOut(tag) {
  95. shown = false
  96. hasSecret = false
  97. newSecret = ''
  98. tokens = []
  99. showHead = shown
  100. showForm = shown
  101. showSecret = shown && hasSecret
  102. showNone = shown && tokens.length == 0
  103. }
  104. on server gitoriaMakeToken(name, session) {
  105. u = userOfSession(session)
  106. if (u == null) { return { error = 'log in with ident (top right) first' } }
  107. return createToken(u.id, name)
  108. }
  109. on server gitoriaRemoveToken(id, session) {
  110. u = userOfSession(session)
  111. if (u == null) { return { error = 'log in with ident (top right) first' } }
  112. return revokeToken(u.id, id)
  113. }
  114. Style {
  115. #tokenerror {
  116. margin = '0'
  117. color = 'var(--color-danger)'
  118. empty { display = 'none' }
  119. }
  120. #tokennotice {
  121. margin = '0'
  122. color = 'var(--color-success)'
  123. }
  124. accessTokens {
  125. display = 'grid'
  126. gap = '.75rem'
  127. minWidth = '0'
  128. // Direct-child universal selectors have no bare language form.
  129. '> *' {
  130. margin = '0'
  131. }
  132. }
  133. #tokenform {
  134. display = 'grid'
  135. gap = '.75rem'
  136. padding = '1rem'
  137. background = 'var(--color-surface)'
  138. borderRadius = 'var(--radius-large)'
  139. // Direct-child universal selectors have no bare language form.
  140. '> *' {
  141. margin = '0'
  142. }
  143. }
  144. #tokensecret {
  145. margin = '0'
  146. padding = '.6rem .8rem'
  147. overflowX = 'auto'
  148. font = '.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  149. color = 'var(--color-text-strong)'
  150. background = 'var(--color-background-sunken)'
  151. borderRadius = 'var(--radius-large)'
  152. }
  153. #tokenlist {
  154. display = 'grid'
  155. gap = '.5rem'
  156. margin = '0'
  157. padding = '0'
  158. listStyle = 'none'
  159. li {
  160. display = 'flex'
  161. flexWrap = 'wrap'
  162. alignItems = 'center'
  163. gap = '.2rem 1rem'
  164. margin = '0'
  165. padding = '.4rem .5rem .4rem 1rem'
  166. background = 'var(--color-surface)'
  167. borderRadius = 'var(--radius-large)'
  168. }
  169. }
  170. #span {
  171. fontWeight = '700'
  172. marginRight = 'auto'
  173. overflowWrap = 'anywhere'
  174. }
  175. }

Branches

Latest commits

  • 477d7bdcMerge branch 'p50'mre
  • 00efc06fP50 reportmre
  • e3f85afblog: commit mention slipmre
  • 4d1a4cf4log: #25 numbersmre
  • 1af0a60ddocs: H25 run() correctionmre
  • eefa2dbcRepo setting: refuse direct pushes to the main branch (pre-receive over HTTPS and ssh)mre
  • 8c8ba2f1log: PR flow announcedmre
  • fa00cd35log: Kunibert pings provenmre
  • 3a68cfaclog: components decisionmre
  • 87de8e31log: Kunibert connected to 9 app reposmre
  • c22aff69log: PR-only rollout startedmre
  • 25309981log: STOP and paused workers 2026-11-08mre
  • 5286803alog: worker briefs and reports of 2026-11-08mre
  • 85c86605log: 2026-11-08 Arachne on list shapemre
  • cb634512log: 2026-11-08 keyed lists livemre
  • 07c98d4aLists: keyed rows with @id, remove(id) and one whole-list assignment instead of hand-rebuilt loopsmre
  • 0db0d81elog: 2026-11-08 day52 live, W30 startedmre
  • b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmre
  • 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
  • f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre