gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb05f6d92b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmreb05f6d92/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. next = [r.row]
  66. for (x of tokens) { if (x.id != r.row.id) { next.push(x) } }
  67. tokens = next
  68. showHead = shown
  69. showForm = shown
  70. showSecret = shown && hasSecret
  71. showNone = shown && tokens.length == 0
  72. }
  73. on removeToken(id) {
  74. r = emit server gitoriaRemoveToken(id)
  75. if (r == null || r.error != null) {
  76. tokenError = r != null ? r.error : 'could not remove the token'
  77. return null
  78. }
  79. tokenError = ''
  80. next = []
  81. for (x of tokens) { if (x.id != id) { next.push(x) } }
  82. tokens = next
  83. showHead = shown
  84. showForm = shown
  85. showSecret = shown && hasSecret
  86. showNone = shown && tokens.length == 0
  87. }
  88. // a login / logout (the shell's faces push them) shows or hides the section
  89. on client gitoriaSignedIn(tag, info) {
  90. shown = true
  91. hasSecret = false
  92. showHead = shown
  93. showForm = shown
  94. showSecret = shown && hasSecret
  95. showNone = shown && tokens.length == 0
  96. }
  97. on client gitoriaSignedOut(tag) {
  98. shown = false
  99. hasSecret = false
  100. newSecret = ''
  101. tokens = []
  102. showHead = shown
  103. showForm = shown
  104. showSecret = shown && hasSecret
  105. showNone = shown && tokens.length == 0
  106. }
  107. on server gitoriaMakeToken(name, session) {
  108. u = userOfSession(session)
  109. if (u == null) { return { error = 'log in with ident (top right) first' } }
  110. return createToken(u.id, name)
  111. }
  112. on server gitoriaRemoveToken(id, session) {
  113. u = userOfSession(session)
  114. if (u == null) { return { error = 'log in with ident (top right) first' } }
  115. return revokeToken(u.id, id)
  116. }
  117. Style {
  118. #tokenerror {
  119. margin = '0'
  120. color = 'var(--color-danger)'
  121. empty { display = 'none' }
  122. }
  123. #tokennotice {
  124. margin = '0'
  125. color = 'var(--color-success)'
  126. }
  127. accessTokens {
  128. display = 'grid'
  129. gap = '.75rem'
  130. minWidth = '0'
  131. // Direct-child universal selectors have no bare language form.
  132. '> *' {
  133. margin = '0'
  134. }
  135. }
  136. #tokenform {
  137. display = 'grid'
  138. gap = '.75rem'
  139. padding = '1rem'
  140. background = 'var(--color-surface)'
  141. borderRadius = 'var(--radius-large)'
  142. // Direct-child universal selectors have no bare language form.
  143. '> *' {
  144. margin = '0'
  145. }
  146. }
  147. #tokensecret {
  148. margin = '0'
  149. padding = '.6rem .8rem'
  150. overflowX = 'auto'
  151. font = '.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  152. color = 'var(--color-text-strong)'
  153. background = 'var(--color-background-sunken)'
  154. borderRadius = 'var(--radius-large)'
  155. }
  156. #tokenlist {
  157. display = 'grid'
  158. gap = '.5rem'
  159. margin = '0'
  160. padding = '0'
  161. listStyle = 'none'
  162. li {
  163. display = 'flex'
  164. flexWrap = 'wrap'
  165. alignItems = 'center'
  166. gap = '.2rem 1rem'
  167. margin = '0'
  168. padding = '.4rem .5rem .4rem 1rem'
  169. background = 'var(--color-surface)'
  170. borderRadius = 'var(--radius-large)'
  171. }
  172. }
  173. #span {
  174. fontWeight = '700'
  175. marginRight = 'auto'
  176. overflowWrap = 'anywhere'
  177. }
  178. }

Branches

Latest commits

  • 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
  • dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
  • 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
  • 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
  • 71b2fa4blog: hybriel#335mre
  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre
  • bf568e14log: V48 mergedmre
  • 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre