gitoria
All repositories: gitoria
5.2 KB
// components/tokens.hl — ACCESS TOKENS (gitoria#7): what a developer's git uses as the PASSWORD to push over HTTPS// (transport.hl). On the main address, for a logged-in user: make a named token — its secret is shown ONCE, right// after it is made (only its hash is stored) — list the own tokens, remove one. Composed into list.hl (`#tokens`).import { infoOfSession, userOfSession, userIdOfSession } from '../lib/users.hl'import { tokenRows, createToken, revokeToken } from '../lib/tokens.hl'session = nullme = infoOfSession(session)shown = me != nullmyUserId = userIdOfSession(session)tokens = myUserId != null ? tokenRows(myUserId) : []showHead = shownshowForm = shownshowSecret = falseshowNone = shown && tokens.length == 0tokenError = ''newSecret = ''hasSecret = falsetokenName = ''View {accessTokens { id = "tokens"if (showHead) { h2 { "Access tokens" } }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." } }if (showForm) {form { id = "tokenform"on submit(e) {e.preventDefault()emit makeToken(e)}label { "Name (for example the computer it is for)"input { id = "tokenname" name = "tokenname" required = "required" maxlength = "60" autocomplete = "off" value = tokenName on input(e) { emit setTokenName(e.target.value) } }}button { id = "tokensave" type = "submit" "Make token" }p { id = "tokenerror" tokenError }}}if (showSecret) { p { id = "tokennotice" "Copy your token now — it is not shown again:" } }if (showSecret) { pre { id = "tokensecret" newSecret } }if (showNone) { p { id = "notokens" class = "muted" "You have no tokens yet." } }ol { id = "tokenlist"for (t of tokens) {li {span { t.name }time { t.created }// Existing theme and test-hook classes have no component Style rule.button { class = "quiet removetoken" type = "button" value = t.@id "Remove" on click(e) { emit removeToken(e.target.value) } }}}}}}// one `if` per element, none inside another (a nested `if` broke the client's repaint on logout)on setTokenName(v) { tokenName = v }on makeToken(e) {r = emit server gitoriaMakeToken(tokenName)if (r == null || r.error != null) {tokenError = r != null ? r.error : 'could not make the token'return null}tokenError = ''tokenName = ''newSecret = r.tokenhasSecret = true// the face's answer can bring `tokens` fresh from the server already (hl:web ships a member derived from// `session` in the ack's sync, hybriel 64527baa) — so the new row is put on top ONCE, never twicetokens.remove(r.row.@id)tokens = [r.row, for (x of tokens) { x }]showHead = shownshowForm = shownshowSecret = shown && hasSecretshowNone = shown && tokens.length == 0}on removeToken(id) {r = emit server gitoriaRemoveToken(id)if (r == null || r.error != null) {tokenError = r != null ? r.error : 'could not remove the token'return null}tokenError = ''tokens.remove(id)showHead = shownshowForm = shownshowSecret = shown && hasSecretshowNone = shown && tokens.length == 0}// a login / logout (the shell's faces push them) shows or hides the sectionon client gitoriaSignedIn(tag, info) {shown = truehasSecret = falseshowHead = shownshowForm = shownshowSecret = shown && hasSecretshowNone = shown && tokens.length == 0}on client gitoriaSignedOut(tag) {shown = falsehasSecret = falsenewSecret = ''tokens = []showHead = shownshowForm = shownshowSecret = shown && hasSecretshowNone = shown && tokens.length == 0}on server gitoriaMakeToken(name, session) {u = userOfSession(session)if (u == null) { return { error = 'log in with ident (top right) first' } }return createToken(u.id, name)}on server gitoriaRemoveToken(id, session) {u = userOfSession(session)if (u == null) { return { error = 'log in with ident (top right) first' } }return revokeToken(u.id, id)}Style {#tokenerror {margin = '0'color = 'var(--color-danger)'empty { display = 'none' }}#tokennotice {margin = '0'color = 'var(--color-success)'}accessTokens {display = 'grid'gap = '.75rem'minWidth = '0'// Direct-child universal selectors have no bare language form.'> *' {margin = '0'}}#tokenform {display = 'grid'gap = '.75rem'padding = '1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'// Direct-child universal selectors have no bare language form.'> *' {margin = '0'}}#tokensecret {margin = '0'padding = '.6rem .8rem'overflowX = 'auto'font = '.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'color = 'var(--color-text-strong)'background = 'var(--color-background-sunken)'borderRadius = 'var(--radius-large)'}#tokenlist {display = 'grid'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.2rem 1rem'margin = '0'padding = '.4rem .5rem .4rem 1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}}#span {fontWeight = '700'marginRight = 'auto'overflowWrap = 'anywhere'}}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 26117255|||PR apps API: review comments on files with spaces in their namemre
- b8796cecMerge branch 'f1-broken-json' into mainGitoria
- 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
- f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
- 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
- 16a3530fMerge branch 'heap-revert' into mainGitoria
- 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
- 13f0c342Merge branch 'hl25-records' into mainGitoria
- a002ecb7|||PR records: HL25 report, heap helper, logmre
- 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre
- 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
- c4f6d9e3reports: G25c growth huntmre
- b88e39f1log: privacy cleanup donemre
- bfd7826ddocs: neutral example organisation namemre