ident
All repositories: gitoria
8.6 KB
// components/apps.hl — `/apps`: THE ACCOUNT'S APPS (piece 2 of 6, ticket #25; CONCEPT.md// "Apps: any ident user can register apps. An app gets an API key.").// Register (name + the origins it runs on), list, edit, new secret, delete. An app has a// public API key and a secret for its server; the secret is shown ONCE, right after it is// made — ident stores only its sha256.//// The faces' names start with `app…`: a face is found by its EVENT NAME across all// files (hl:web), so they must not collide with home.hl's.parent './main.hl'import { accountOfSession } from '../lib/accounts.hl'import { appRows, createApp, updateApp, regenerateSecret, deleteApp } from '../lib/apps.hl'import { siteName } from '../project.hl'import { leadLook, messageLook, noticeLook } from './styles.hl'session = nullme = accountOfSession(&session)signedIn = me != nullsignedOut = me == nullmeEmail = me != null ? me.email : ''apps = me != null ? appRows(me.id) : []hasApps = apps.length > 0noApps = apps.length == 0__title = siteName + ' | your apps'// THE APP FORM — new and editediting = falseeditId = '' // '' = a new app, else the app's id (a UUID)editHeading = ''fName = ''fOrigins = ''// THE SECRET, shown onceshowSecret = falsesecretFor = ''secret = ''message = ''notice = ''Style {pLead = leadLookpMessage = messageLookpNotice = noticeLookappMain {flex = '1 1 14rem'display = 'grid'gap = '.15rem'minWidth = '0'}appName {fontWeight = '700'color = 'var(--color-text-strong)'overflowWrap = 'anywhere'}appOrigins {color = 'var(--color-text-muted)'fontSize = '.875rem'overflowWrap = 'anywhere'}appKey {fontSize = '.875rem'color = 'var(--color-text-muted)'overflowWrap = 'anywhere'}// the secret, shown oncesecretBox {display = 'grid'gap = '.6rem'padding = '1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'h2 {color = 'var(--color-warning)'}code {display = 'block'padding = '.5rem .6rem'background = 'var(--color-background-sunken)'userSelect = 'all'}}}View {identCard {if (signedOut) {h1 { "Your apps" }p { id = "signinfirst" Style.pLead "Sign in to ident first: " a { href = "/" "sign in" } "." }}if (signedIn) {accountBar {userEmail { id = "meemail" meEmail }a { id = "toidentities" href = "/" "Your identities" }}if (showSecret) {secretBox { id = "secretbox"h2 { "Secret of " secretFor }p { Style.pLead "Shown only now — copy it to your app's server. Its API calls (the code exchange) use it; it never goes into a web page. Lost it? Make a new one." }code { id = "secret" secret }button { id = "secretdone" type = "button" class = "small" "I copied it" on click(e) { emit hideSecret(e) } }}}if (editing) {form { id = "appform"on submit(e) {e.preventDefault()emit saveApp(e)}h1 { id = "appformheading" editHeading }label { "Name"input { id = "fappname" name = "name" maxlength = "60" autocomplete = "off" required = "required" value = fName on input(e) { emit setName(e.target.value) } }}label { "Origins " fieldHint { "(where the app runs, like https://tickets.worldapi.org — several separated by spaces; the login button only returns there)" }input { id = "forigins" name = "origins" autocomplete = "off" required = "required" value = fOrigins on input(e) { emit setOrigins(e.target.value) } }}formButtons {button { id = "saveapp" type = "submit" "Save" }button { id = "cancelapp" type = "button" class = "quiet" "Cancel" on click(e) { emit closeForm(e) } }}}}section { id = "appssection"sectionHead {h1 { "Your apps" }button { id = "newapp" type = "button" class = "small" "Register an app" on click(e) { emit openNew(e) } }}if (noApps) { p { id = "noapps" Style.pLead "No apps yet. An app you register gets an API key for its “login with ident” button." } }ul { id = "apps"for (row of apps) {li {appMain {appName { row.name }appOrigins { row.originsText }appKey { "API key " code { row.apiKey } }}identityActions {button { type = "button" class = "quiet small" name = "edit" value = row.id "Edit" on click(e) { emit openEdit(e.target.value) } }button { type = "button" class = "quiet small" name = "newsecret" value = row.id "New secret" on click(e) { emit renew(e.target.value) } }button { type = "button" class = "quiet small danger" name = "delete" value = row.id "Delete" on click(e) { emit remove(e.target.value) } }}}}}}}p { id = "notice" Style.pNotice notice }p { id = "message" Style.pMessage message }}}on setName(v) { fName = v }on setOrigins(v) { fOrigins = v }rowOf = (id) => {for (row of apps) { if ('' + row.id == '' + id) { return row } }return null}// the origins field: words separated by spaces or commasoriginList = (text) => {out = []for (w of text.replaceAll(',', ' ').split(' ')) {let t = w.trim()if (t != '') { out.push(t) }}return out}setApps = (list) => {apps = listhasApps = list.length > 0noApps = list.length == 0return null}on openNew(e) {message = ''notice = ''editId = ''fName = ''fOrigins = ''editHeading = 'Register an app'editing = true}on openEdit(id) {message = ''notice = ''row = rowOf(id)if (row == null) { return null }editId = row.idfName = row.namefOrigins = row.originsTexteditHeading = 'Edit ' + row.nameediting = true}on closeForm(e) {editing = falsemessage = ''}on hideSecret(e) {showSecret = falsesecret = ''secretFor = ''}on saveApp(e) {message = ''notice = ''input = { name = fName origins = originList(fOrigins) }let r = nullif (editId == '') {r = emit server appCreate(input)} else {r = emit server appUpdate('' + editId, input)}if (r == null) {message = 'the server did not answer — try again'return null}if (r.error != null) {message = r.errorreturn null}setApps(r.apps)editing = falseif (r.secret != null) {secretFor = r.app.namesecret = r.secretshowSecret = truenotice = 'App registered.'} else {notice = 'App saved.'}}on renew(id) {message = ''notice = ''row = rowOf(id)if (row == null) { return null }if (!confirm('Make a new secret for “' + row.name + '”? The current one stops working at once.')) { return null }r = emit server appNewSecret('' + id)if (r == null) {message = 'the server did not answer — try again'return null}if (r.error != null) {message = r.errorreturn null}setApps(r.apps)secretFor = r.app.namesecret = r.secretshowSecret = truenotice = 'New secret made.'}on remove(id) {message = ''notice = ''row = rowOf(id)if (row == null) { return null }if (!confirm('Delete the app “' + row.name + '”? Its API key stops working and the ids its users had in it are gone.')) { return null }r = emit server appDelete('' + id)if (r == null) {message = 'the server did not answer — try again'return null}if (r.error != null) {message = r.errorreturn null}setApps(r.apps)if ('' + editId == '' + id) { editing = false }showSecret = falsesecret = ''notice = 'App deleted.'}// ---- the faces ------------------------------------------------------------------------// The LAST parameter is the session (the framework appends it); accountOfSession only// gets the framework's own Session (hl:web never takes it from the peer, hybriel#16/#31).on server appCreate(input, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = createApp(me.id, input)if (r.error != null) { return r }return { app = r.app secret = r.secret apps = appRows(me.id) }}on server appUpdate(id, input, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = updateApp(me.id, id, input)if (r.error != null) { return r }return { app = r.app apps = appRows(me.id) }}on server appNewSecret(id, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = regenerateSecret(me.id, id)if (r.error != null) { return r }return { app = r.app secret = r.secret apps = appRows(me.id) }}on server appDelete(id, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = deleteApp(me.id, id)if (r.error != null) { return r }return { deleted = r.deleted apps = appRows(me.id) }}
Branches
Latest commits
- 3c33d6eaident#34: the connection link in inbox has no class (rule on #conns a)mre
- dc97ec0dident#34: the Notif. chip and the Used in link share chipLook (Style.pChip) instead of the classes chip/used/notifmre
- 378bd432ident#34: the identity picture look is a static in styles.hl (Style.pAvatar); sizes stay with each listmre
- 1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre
- ddc7d135Merge branch 'f7-hooks' into mainIdent
- eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
- ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
- 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
- 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
- 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
- 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
- 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
- e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
- fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre
- 9f2ad803ident#34: notification switches: push/email by name=..., locked by aria-disabled, the switch look is the role=switch button (no switch/push/email/locked classes)mre
- e0f0ddaaident#34: inbox: the Mark read/unread button is styled as the button of its note-foot, the icon is found as the row's img (no toggle/icon classes)mre
- 16b49756ident#34: unused row classes (choice, usedrow, kind, shortid) droppedmre
- f9d6fb38ident#34: apps and identity rows: the Edit/New secret/Delete buttons carry name=..., the API key is found by its element; unused row classes (app, identity, shortid) droppedmre
- b323265aMerge branch 'f5-styles' into mainIdent
- 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre