gitoria
All repositories: gitoria
3.7 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 } from '../users.hl'import { tokenRows, createToken, revokeToken } from '../tokens.hl'session = nullme = infoOfSession(session)shown = me != nullmyUser = userOfSession(session)tokens = myUser != null ? tokenRows(myUser.id) : []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) {let 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 = truelet next = [r.row]for (x of tokens) { next.push(x) }tokens = nextshowHead = shownshowForm = shownshowSecret = shown && hasSecretshowNone = shown && tokens.length == 0}on removeToken(id) {let r = emit server gitoriaRemoveToken(id)if (r == null || r.error != null) {tokenError = r != null ? r.error : 'could not remove the token'return null}tokenError = ''let 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) {let 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) {let u = userOfSession(session)if (u == null) { return { error = 'log in with ident (top right) first' } }return revokeToken(u.id, id)}
Branches
- mainmain branch
Latest commits
- 4a2d7125initial commitmre