ident
All repositories: gitoria
10.9 KB
// components/home.hl — `/` and `/signin/:rid`: ALL OF IDENT (pieces 1+2, tickets #24 #25;// CONCEPT.md).// Signed out: email → a six-digit code by mail → signed in. There is no registration:// the first right code for an address creates the account with a DEFAULT IDENTITY, then// this page shows that identity's name fields and says they are optional (Skip).// Signed in: the account's identities (list, new, edit, delete — never the last one)// and its time zone (the browser's at the first login; changeable here).//// Under `/signin/<rid>` the page belongs to an APP'S LOGIN BUTTON (lib/apps.hl requestOf):// it names the app, signs in to ident if needed, then asks WHICH IDENTITY the app gets// (with a single identity it still shows which one, one click) and sends the browser back// to the app with a one-time code. Managing identities stays on `/`.//// Every step takes the server's answer from the CALL (the value form of emit): it rides// the ack, over the socket or the POST fallback.parent './main.hl'import { accountOfSession } from '../lib/accounts.hl'import { recordPending, dropPending } from '../lib/login.hl'import { identityRows } from '../lib/identities.hl'import { requestOf } from '../lib/apps.hl'import { navigate } from 'hl:web'import EmailStep from './emailstep.hl'import CodeStep from './codestep.hl'import IdentityForm from './identityform.hl'import ChooseIdentity from './chooseidentity.hl'import IdentityList from './identitylist.hl'import TimeZone from './timezone.hl'import { siteName } from '../project.hl'session = nullrid = null// 'code' on THE CODE PAGE `/code` and `/signin/<rid>/code` (ident#20; lib/api.hl codePage// renders this component there, only while the session has a pending code), else nullstep = nullonCodePage = step == 'code'// the pending address, read by codePage from the session and handed in as a param (mission// 048): read here from the session, hl:web (64527baa) would re-derive it after EVERY face// that takes the session — after the 5th wrong code it turned null and the code form// vanished with nothing to click (gate "after 5 wrong tries even the RIGHT code is refused")pending = null// where this login lives: the email form, and the code page after "Send me a code"homeUrl = rid != null ? '/signin/' + rid : '/'codeUrl = rid != null ? '/signin/' + rid + '/code' : '/code'me = accountOfSession(&session)signedIn = me != null// THE APP'S LOGIN REQUEST (null on `/`, or when unknown / expired)request = rid != null ? requestOf(rid) : nullforApp = request != nullbadRequest = rid != null && request == nullappName = request != null ? request.app.name : ''appOrigin = request != null ? request.origin : ''forInvite = request != null && request.invite != ''requestLead = forInvite ? 'You are invited to ' : 'Sign in to 'onWelcome = step == 'welcome' && me != null && forApp // a NEW address sent here from the selector's frame (ident#31): the default identity's form firstchoosing = forApp && me != null && !onWelcome // the identity choice for the appmanage = rid == null && me != null // identities + time zone (only on `/`)meEmail = me != null ? me.email : ''timeZone = me != null ? me.timeZone : ''identities = me != null ? identityRows(me.id) : []__title = siteName + (forApp ? ' | sign in to ' + appName : (me != null ? ' | your identities' : ' | sign in'))// the login steps (a View's `if` takes a member, so each step is one).// THE CODE STEP IS ITS OWN PAGE (ident#20, creator: "just make a /code where it checks a// pending code"): "Send me a code" records the address in this browser's session (face// rememberPending) and goes to `/code`; that page shows the code form for the session's// pending address (lib/login.hl pendingOf) — so a reload, a second tab or a re-seed keeps it.pendingEmail = onCodePage && me == null && !badRequest ? pending : nullaskEmail = me == null && !badRequest && !onCodePageaskCode = pendingEmail != nullsentTo = pendingEmail != null ? pendingEmail : ''message = ''notice = ''// THE IDENTITY FORM — new, edit, and right after the first login the default identity// ("welcome": the names are optional, Skip closes it)editing = onWelcomewelcome = onWelcomeeditId = '' // '' = a new identity, else the identity's id (a UUID)// the default identity the welcome form (/signin/<rid>/welcome) edits. It is its OWN member: `editId` must stay a plain value (a member made of an// expression is recomputed when `identities` changes, which reset the id of every identity edited on `/`)welcomeId = onWelcome ? '' + identities[0].id : ''editHeading = onWelcome ? 'Welcome — name your default identity' : ''fIdentityName = ''fNickname = ''fFirstname = ''fLastname = ''fAvatar = ''hasAvatarPreview = falseStyle {appRequest {display = 'block'padding = '.7rem .8rem'color = 'var(--color-text)'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'overflowWrap = 'anywhere'}requestOrigin {display = 'block'color = 'var(--color-text-muted)'fontSize = '.875rem'}}View {identCard {if (forApp) {appRequest { id = "apprequest" requestLead strong { id = "appname" appName } " " requestOrigin { id = "apporigin" appOrigin } }}if (badRequest) {h1 { "Login request expired" }p { id = "badrequest" class = "message" "This login request is unknown or expired. Go back to the app and start the login again." }}if (askEmail) {h1 { "Sign in" }p { class = "lead" "We mail you a one-time code. There are no passwords, and no sign-up: the first login with an address creates its account." }EmailStep {}}if (askCode) {h1 { "Enter your code" }CodeStep { sentTo = sentTo tail = ". It is valid for 10 minutes." }}if (signedIn) {if (editing) {IdentityForm { editHeading = editHeading welcome = welcome editId = editId welcomeId = welcomeId fIdentityName = fIdentityName fNickname = fNickname fFirstname = fFirstname fLastname = fLastname fAvatar = fAvatar hasAvatarPreview = hasAvatarPreview }}if (choosing) {ChooseIdentity { rid = rid appName = appName identities = identities }}if (manage) {IdentityList { identities = identities }TimeZone { timeZone = timeZone }}}p { id = "notice" class = "notice" notice }p { id = "message" class = "message" message }}}// a placed component shows its answer here (the #message and #notice lines under the card)status = (String text, String note) => {message = textnotice = note}// the email step (components/emailstep.hl) asked for a code (a plain POST to /api/code, lib/api.hl) and one is on its way.// THE SESSION REMEMBERS THE STEP, then the browser goes to the code page. A function route gets no session (hybriel#11), so the// face records it; it refuses unless a code for the address is really waiting.emailSent = (String address) => {k = emit server rememberPending(address)if (k == null) {message = 'the server did not answer — try again'return null}if (k.error != null) {message = k.errorreturn null}navigate(codeUrl)}// the code step (components/codestep.hl) checked the code: why not, or the signed-in accountcodeFailed = (String text) => { message = text }codeVerified = (r) => {askCode = false// signed in: the address bar leaves the code page (a reload of /code would go back// to it anyway — lib/api.hl codePage sends a signed-in browser there)window.history.replaceState(null, '', homeUrl)meEmail = r.account.emailtimeZone = r.account.timeZoneidentities = r.identitiessignedIn = truenotice = ''manage = !forAppchoosing = forApp// the shell (components/main.hl) shows the user menu from the account: a page's emit reaches every level above it// (hybriel#193), so the header follows the in-place sign-in without a reload — the welcome form below stays in placeemit shellSession(r.account.email)// THE FIRST LOGIN: the default identity's names, optional (for an app too: the// choice follows once the form is saved or skipped)if (r.created) {fillForm(r.identities[0])editHeading = 'Welcome — name your default identity'welcome = trueediting = truechoosing = false}}// THE IDENTITY FORM (components/identityform.hl) is opened with the values to start from; what the user types is handed up by setFfillForm = (row) => {editId = row.idfIdentityName = row.identityNamefNickname = row.nicknamefFirstname = row.firstnamefLastname = row.lastnamefAvatar = row.avatarhasAvatarPreview = row.hasAvatarreturn null}rowOf = (id) => {for (row of identities) { if ('' + row.id == '' + id) { return row } }return null}openNew = () => {message = ''notice = ''editId = ''fIdentityName = ''fNickname = ''fFirstname = ''fLastname = ''fAvatar = ''hasAvatarPreview = falseeditHeading = 'New identity'welcome = falseediting = true}openEdit = (id) => {message = ''notice = ''row = rowOf(id)if (row == null) { return null }fillForm(row)editHeading = 'Edit ' + row.labelwelcome = falseediting = true}setF = (String name, String v) => {if (name == 'identityName') { fIdentityName = v }if (name == 'nickname') { fNickname = v }if (name == 'firstname') { fFirstname = v }if (name == 'lastname') { fLastname = v }if (name == 'avatar') { fAvatar = v hasAvatarPreview = v.trim() != '' }}closeForm = () => {editing = falsewelcome = falsemessage = ''choosing = forApp}formSaved = (rows, String text) => {identities = rowsnotice = textediting = falsewelcome = falsechoosing = forApp}// the identity list (components/identitylist.hl) deleted an identityidentitiesDeleted = (rows, String id) => {identities = rowsif ('' + editId == id) { editing = false }notice = 'Identity deleted.'}// the time zone component (components/timezone.hl) saved the account's zonezoneSaved = (String zone) => {timeZone = zonenotice = 'Time zone saved.'}// "Other address": the session forgets the pending sign-in, back to the email formback = () => {message = ''r = emit server forgetPending()navigate(homeUrl)}// ---- the faces ------------------------------------------------------------------------// A face's LAST parameter is the session (the framework appends it). Every face that// needs the account asks accountOfSession, which only accepts the framework's Session.// A face runs on a BLANK instance: it has its arguments and its imports, not this// component's members or functions.// (the code request is NOT a face since mission 010: POST /api/code in lib/api.hl — a face// sees no request headers, so it could not apply the per-IP limit; a face here would be a// way around it)// THE PENDING SIGN-IN (ident#20): recorded after POST /api/code answered, only while a// code for that address is really waiting (lib/login.hl recordPending); "Other address"// forgets it. Named apart from the store functions (faces dispatch by name, hybriel#36).on server rememberPending(email, session) {return recordPending(&session, email)}on server forgetPending(session) {return dropPending(&session)}
Branches
Latest commits
- f2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemre
- 8370b748ident#33: the app request box moves into home.hl's Stylemre
- 40bf3b97ident#33: the 404 page's home link rule moves into notfound.hlmre
- 40627a89ident#33: the time zone section's spacing moves into timezone.hlmre
- d389db08ident#33: the identity page's rules and the Notif. chip move into identity.hl's Stylemre
- ddda0b5bident#33: the identity row's parts move into identitylist.hl's Stylemre
- 47e516afident#33 ident#34: the identity form's avatar rules move into identityform.hl; the preview and Remove button are hidden with the hidden attribute instead of built class strings (avatarPreviewClass, avatarRemoveClass gone)mre
- 5cb5cf0eident#33: the code field's look moves into codestep.hl's Stylemre
- f421cd60ident#33: the shell's own rules (user menu address, offline note, network probe) move into main.hl's Stylemre
- c512fb96Merge branch 'f4-homesplit' into mainIdent
- 07d1717c|||PR ident#40 home.hl is split into components, one per area: email step, identity form, identity list, app identity choice, time zone; each moves its faces with it, the email step is shared with embed.hl (#40.3, rest of #40.2)mre
- 59e8fcc1ident#40.3: the app's identity choice is one component (components/chooseidentity.hl); its face chooseIdentity moves with itmre
- e23efdfcident#40.3: the identity list is one component (components/identitylist.hl); its delete and face dropIdentity move with itmre
- e24b59a6ident#40.3: the time zone is one component (components/timezone.hl); its face changeTimeZone moves with itmre
- 8cbc5717ident#40.3: the email step is one component (components/emailstep.hl) placed by home.hl and embed.hlmre
- 6fad3bd2Merge branch 'f3-codestep' into mainIdent
- 51e387f2|||PR ident#40 the code step is one component (components/codestep.hl) placed by home.hl and embed.hl; its verify face, setCode, browserZone and verify call exist once (#40.2)mre
- c28bddeeMerge branch 'f2-shell' into mainIdent
- c3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mre
- 060f3870ident#40.4: use the shell sign-out faces in regression gatesmre