gitoria
All repositories: gitoria
4.0 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" class = "message" tokenError }}}if (showSecret) { p { id = "tokennotice" class = "notice" "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 { class = "slug" t.name }time { t.created }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 twicenext = [r.row]for (x of tokens) { if (x.id != r.row.id) { next.push(x) } }tokens = nextshowHead = 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 = ''next = []for (x of tokens) { if (x.id != id) { next.push(x) } }tokens = nextshowHead = 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)}
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
- a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
- 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
- 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
- 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
- a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
- 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
- c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre
- e307d69agitoria: say what is per process during the hand-overmre
- f0cbe6a6gitoria: standby service on port 45014 and a deploy that hands over through it without a gapmre
- 727cd083gitoria#25: README: vendor notes for Hybriel c1b1010f and the page cachemre
- 61b72dedgitoria#25: re-vendor Hybriel master c1b1010f (W149 page cache), key the repo Readme page by slug and main commit, extend the readme-cache gatemre
- 5b0b4b9ereadme-cache gate: use the security gate's ports when no own ports are givenmre
- bc8f20d9gitoria#25: re-vendor Hybriel c09538bb with the W141 render cache, cache the homepage per commit, add the readme-cache gatemre
- 9feebbd3Re-vendor Hybriel to ded47c13 (W145: Firefox start script fix)mre
- 28ed41e5gitoria#24: one sign-in comes from hl:web batch 20, the /session/share workaround is gonemre
- 3b2669e4gs: drop the unbuildable legacy check, fix pwa fetchmre
- 2a2fdd77gs: C2 check before cookie experimentsmre
- 76e0587aWIP gs 2mre
- a80da7bdWIP gs: security gate for lazy sessions, g24 browser checksmre
- 23fb05d8re-vendor Hybriel aaa39e69 (hl:web batch 20: login emit and Sessions.mint, tab follows a login, signed-in session cookie wins among duplicates and is re-issued with the Domain, W85 faster render, lazy sessions)mre