ident
All repositories: gitoria
6.1 KB
// components/embed.hl — `/embed/signin?key=<api key>&return=<url>` (ident#31): THE SELECTOR'S SIGN-IN, shown inside the selector's// panel on an app's page (an iframe; lib/api.hl embedSignin checks key + return, parks the request like the login button and allows// framing only by the app's registered origins). Signed out of ident: email → code → the identity list, all in this frame, with one// note that this signs the user in to ident. Choosing an identity (the identity row itself, no extra Continue click), and the way on for a NEW address, are plain links with// target="_top": the whole app page then goes to `<return>?ident_code=<code>` (lib/api.hl embedGo), the flow every app handles.// A new address (the account is created by the first right code) is sent on to ident in the same tab (`/signin/<rid>/welcome`)// to name its identity and pick it; ident then sends the browser back to the page it came from.parent './embedshell.hl'import { accountOfSession } from '../lib/accounts.hl'import EmailStep from './emailstep.hl'import CodeStep from './codestep.hl'import { identityRows } from '../lib/identities.hl'import { requestOf } from '../lib/apps.hl'import { leadLook, messageLook } from './styles.hl'session = nullrid = nullme = accountOfSession(&session)request = rid != null ? requestOf(rid) : nullappName = request != null ? request.app.name : ''identities = me != null ? identityRows(me.id) : []// the steps (a View's `if` takes a member): email → code → choose (or `fresh` for a new address)askEmail = me == nullaskCode = falsechoose = me != nullfresh = falsesentTo = ''message = ''rowsOf = (list) => {out = []for (row of list) { out.push({ label = row.label shortId = row.shortId href = '/embed/go?rid=' + rid + '&identity=' + row.id }) }return out}choices = rowsOf(identities)newHref = '/signin/' + rid + '/welcome'// the selector's sign-in frame (ident#31): inside the selector's panel (same surface colour), the same fields and buttonsStyle {pLead = leadLookpMessage = messageLook'html:has(embed-card), body:has(embed-card)' {background = 'var(--color-surface)'}fitMark {position = 'absolute'width = '0'height = '0'overflow = 'hidden'animation = 'ident-frame-fit 1s infinite'}'@keyframes ident-frame-fit' = {'from' = { opacity = '1' }to = { opacity = '0.99' }}embedCard {display = 'grid'gap = '.8rem'padding = '.5rem'}'embed-card p' {margin = '0'overflowWrap = 'anywhere'}'embed-card, embed-card form, embed-card label, embed-card input, embed-card li' {minWidth = '0'}'embed-card input' {width = '100%'maxWidth = '100%'boxSizing = 'border-box'}'embed-card #code' {fontSize = '1.2rem'letterSpacing = '.15em'}'embed-card form' {display = 'grid'gap = '.8rem'}'embed-card label' {display = 'grid'gap = '.25rem'marginBottom = '0'}'embed-card .message:empty' {display = 'none'}'embed-card .lead' {color = 'var(--color-text-muted)'}'embed-card #chooselist' {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.5rem'}'embed-card #chooselist li' {background = 'var(--color-background-sunken)'flexWrap = 'nowrap'}'embed-card identity-main' {flex = '1 1 auto'}'embed-card #chooselist a' {display = 'flex'flex = '1 1 auto'alignItems = 'center'minHeight = 'var(--layout-tap)'color = 'inherit'textDecoration = 'none'}'embed-card a.button' {display = 'inline-flex'alignItems = 'center'justifyContent = 'center'minHeight = 'var(--layout-tap)'textDecoration = 'none'}}View {embedCard {if (askEmail) {fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }p { id = "embednote" Style.pLead "This signs you in to ident. We mail you a one-time code." }EmailStep {}}if (askCode) {fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }CodeStep { sentTo = sentTo tail = '.' }}if (choose) {fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }p { Style.pLead "You are signed in to ident. Choose the identity to log in to " strong { appName } " with." }ul { id = "chooselist"for (row of choices) {li {a { class = "choose" target = "_top" href = row.hrefidentityMain { identityLabel { row.label } identityShortId { row.shortId } }}}}}}if (fresh) {fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }p { id = "freshnote" Style.pLead "This address is new to ident, so it has an account now. Create your identity on ident: it takes you there and brings you back to this page." }a { id = "gonew" class = "button" target = "_top" href = newHref "Create my identity" }}p { id = "message" Style.pMessage message }}}// THE FRAME'S HEIGHT: the selector (selector.js) cannot read this page's height across origins, so the page tells it. Every step has a// fitMark whose CSS animation starts when the step appears (and repeats each second for a resize or a message): then the page's content// height goes to the parent window. No JavaScript of ours; selector.js accepts it from ident's origin only.on fit(e) {// the card's bottom edge, not the document's height (the document is as tall as the frame, so it could never shrink)card = document.querySelector('embed-card')if (card != null) { window.parent.postMessage({ identFrameHeight = Math.ceil(card.getBoundingClientRect().bottom + window.scrollY) }, '*') }}// the email step (components/emailstep.hl) asked for a code (the plain POST to /api/code): the frame goes on to the code stepemailSent = (String address) => {sentTo = addressaskEmail = falseaskCode = true}// the code step (components/codestep.hl) checked the code: the answer, or why notcodeFailed = (String text) => { message = text }codeVerified = (r) => {askCode = falseidentities = r.identitieschoices = rowsOf(r.identities)if (r.created) {fresh = true} else {choose = true}}back = () => {message = ''askCode = falseaskEmail = true}
Branches
Latest commits
- 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
- 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
- 5d1b3fedMerge branch 'v61-day61' into mainIdent
- 83faeb15|||PR ident: vendor Hybriel day61mre
- b2572b34Merge branch 'v59-day59' into mainIdent
- 67cf016d|||PR ident: vendor Hybriel day59mre
- 600c043dMerge branch 'v58-day58' into mainIdent
- 365f8c80|||PR ident: vendor Hybriel day58mre
- 585126e5Merge branch 'f16-setf' into mainIdent
- 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
- a1419d9cMerge branch 'f15-navigate' into mainIdent
- 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
- e36f4516Merge branch 'f14-online' into mainIdent
- 2c5eac91|||PR ident#38 online state without probe timermre
- bf1980f2Merge branch 'v56-day56' into mainIdent
- 62ae0adf|||PR ident: vendor Hybriel day56mre
- 0d18abc4Merge branch 'f13-avatar' into mainIdent
- 2a99730a|||PR ident#37 avatar in hlmre
- fa4ed25bMerge branch 'f11-upsert' into mainIdent
- 8f3d9bc9|||PR ident#42 keyed upsert and removemre