ident
All repositories: gitoria
2.5 KB
// components/codestep.hl — THE CODE STEP of the sign-in (ident#40.2): the one-time-code form, placed by components/home.hl (the code page)// and components/embed.hl (the selector's frame). The host passes in WHO the code was sent to (sentTo) and the sentence's ending (tail);// this component owns the code field, the browser's time zone and the check against the server (face verifyCode, lib/login.hl// signInWithCode). What follows is the host's: it gets the answer through $parent.codeVerified(r) or $parent.codeFailed(text), and// "Other address" is $parent.back(). Markup, ids and look are those both pages had before (the CSS is components/styles.hl).import { signInWithCode } from '../lib/login.hl'import { leadLook } from './styles.hl'sentTo = ''tail = '.'code = ''Style {pLead = leadLook'#code' {fontSize = '1.4rem'letterSpacing = '.3em'fontVariantNumeric = 'tabular-nums'}}View {p { id = "sentto" Style.pLead "We sent a six-digit code to " strong { sentTo } tail }form { id = "codeform"on submit(e) {e.preventDefault()emit verify(e)}label { "One-time code"input { id = "code" name = "code" autocomplete = "one-time-code" inputmode = "numeric" pattern = "[0-9]{6}" maxlength = "6" required = "required" value = code on input(e) { emit setCode(e.target.value) } }}formButtons {button { id = "verify" type = "submit" "Sign in" }button { id = "back" type = "button" class = "quiet" "Other address" on click(e) { $parent.back() } }}}}on setCode(v) { code = v }// the browser's own time zone (IANA name) goes with the first login (`Intl` is a browser global of client code, hybriel#18)browserZone = () => { return Intl.DateTimeFormat().resolvedOptions().timeZone }on verify(e) {$parent.codeFailed('')r = emit server verifyCode(sentTo, code, browserZone())if (r == null) {$parent.codeFailed('the server did not answer — try again')return null}if (r.error != null) {$parent.codeFailed(r.error)return null}$parent.codeVerified(r)}// the right code signs the session in; the first one for an address creates the account, its default identity and stores the// browser's time zoneon server verifyCode(email, code, timeZone, session) {if (session == null) { return { error = 'no session — reload the page' } }if (email == null || hlTypeName(email) != 'String' || code == null || hlTypeName(code) != 'String') { return { error = 'email and code must be strings' } }return signInWithCode(&session, email, code, timeZone)}
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