gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf2d9f79ff2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemref2d9f79f/components/home.hl

10.9 KB

  1. // components/home.hl — `/` and `/signin/:rid`: ALL OF IDENT (pieces 1+2, tickets #24 #25;
  2. // CONCEPT.md).
  3. // Signed out: email → a six-digit code by mail → signed in. There is no registration:
  4. // the first right code for an address creates the account with a DEFAULT IDENTITY, then
  5. // this page shows that identity's name fields and says they are optional (Skip).
  6. // Signed in: the account's identities (list, new, edit, delete — never the last one)
  7. // and its time zone (the browser's at the first login; changeable here).
  8. //
  9. // Under `/signin/<rid>` the page belongs to an APP'S LOGIN BUTTON (lib/apps.hl requestOf):
  10. // it names the app, signs in to ident if needed, then asks WHICH IDENTITY the app gets
  11. // (with a single identity it still shows which one, one click) and sends the browser back
  12. // to the app with a one-time code. Managing identities stays on `/`.
  13. //
  14. // Every step takes the server's answer from the CALL (the value form of emit): it rides
  15. // the ack, over the socket or the POST fallback.
  16. parent './main.hl'
  17. import { accountOfSession } from '../lib/accounts.hl'
  18. import { recordPending, dropPending } from '../lib/login.hl'
  19. import { identityRows } from '../lib/identities.hl'
  20. import { requestOf } from '../lib/apps.hl'
  21. import { navigate } from 'hl:web'
  22. import EmailStep from './emailstep.hl'
  23. import CodeStep from './codestep.hl'
  24. import IdentityForm from './identityform.hl'
  25. import ChooseIdentity from './chooseidentity.hl'
  26. import IdentityList from './identitylist.hl'
  27. import TimeZone from './timezone.hl'
  28. import { siteName } from '../project.hl'
  29. session = null
  30. rid = null
  31. // 'code' on THE CODE PAGE `/code` and `/signin/<rid>/code` (ident#20; lib/api.hl codePage
  32. // renders this component there, only while the session has a pending code), else null
  33. step = null
  34. onCodePage = step == 'code'
  35. // the pending address, read by codePage from the session and handed in as a param (mission
  36. // 048): read here from the session, hl:web (64527baa) would re-derive it after EVERY face
  37. // that takes the session — after the 5th wrong code it turned null and the code form
  38. // vanished with nothing to click (gate "after 5 wrong tries even the RIGHT code is refused")
  39. pending = null
  40. // where this login lives: the email form, and the code page after "Send me a code"
  41. homeUrl = rid != null ? '/signin/' + rid : '/'
  42. codeUrl = rid != null ? '/signin/' + rid + '/code' : '/code'
  43. me = accountOfSession(&session)
  44. signedIn = me != null
  45. // THE APP'S LOGIN REQUEST (null on `/`, or when unknown / expired)
  46. request = rid != null ? requestOf(rid) : null
  47. forApp = request != null
  48. badRequest = rid != null && request == null
  49. appName = request != null ? request.app.name : ''
  50. appOrigin = request != null ? request.origin : ''
  51. forInvite = request != null && request.invite != ''
  52. requestLead = forInvite ? 'You are invited to ' : 'Sign in to '
  53. onWelcome = step == 'welcome' && me != null && forApp // a NEW address sent here from the selector's frame (ident#31): the default identity's form first
  54. choosing = forApp && me != null && !onWelcome // the identity choice for the app
  55. manage = rid == null && me != null // identities + time zone (only on `/`)
  56. meEmail = me != null ? me.email : ''
  57. timeZone = me != null ? me.timeZone : ''
  58. identities = me != null ? identityRows(me.id) : []
  59. __title = siteName + (forApp ? ' | sign in to ' + appName : (me != null ? ' | your identities' : ' | sign in'))
  60. // the login steps (a View's `if` takes a member, so each step is one).
  61. // THE CODE STEP IS ITS OWN PAGE (ident#20, creator: "just make a /code where it checks a
  62. // pending code"): "Send me a code" records the address in this browser's session (face
  63. // rememberPending) and goes to `/code`; that page shows the code form for the session's
  64. // pending address (lib/login.hl pendingOf) — so a reload, a second tab or a re-seed keeps it.
  65. pendingEmail = onCodePage && me == null && !badRequest ? pending : null
  66. askEmail = me == null && !badRequest && !onCodePage
  67. askCode = pendingEmail != null
  68. sentTo = pendingEmail != null ? pendingEmail : ''
  69. message = ''
  70. notice = ''
  71. // THE IDENTITY FORM — new, edit, and right after the first login the default identity
  72. // ("welcome": the names are optional, Skip closes it)
  73. editing = onWelcome
  74. welcome = onWelcome
  75. editId = '' // '' = a new identity, else the identity's id (a UUID)
  76. // 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
  77. // expression is recomputed when `identities` changes, which reset the id of every identity edited on `/`)
  78. welcomeId = onWelcome ? '' + identities[0].id : ''
  79. editHeading = onWelcome ? 'Welcome — name your default identity' : ''
  80. fIdentityName = ''
  81. fNickname = ''
  82. fFirstname = ''
  83. fLastname = ''
  84. fAvatar = ''
  85. hasAvatarPreview = false
  86. Style {
  87. appRequest {
  88. display = 'block'
  89. padding = '.7rem .8rem'
  90. color = 'var(--color-text)'
  91. background = 'var(--color-surface)'
  92. borderRadius = 'var(--radius-large)'
  93. overflowWrap = 'anywhere'
  94. }
  95. requestOrigin {
  96. display = 'block'
  97. color = 'var(--color-text-muted)'
  98. fontSize = '.875rem'
  99. }
  100. }
  101. View {
  102. identCard {
  103. if (forApp) {
  104. appRequest { id = "apprequest" requestLead strong { id = "appname" appName } " " requestOrigin { id = "apporigin" appOrigin } }
  105. }
  106. if (badRequest) {
  107. h1 { "Login request expired" }
  108. p { id = "badrequest" class = "message" "This login request is unknown or expired. Go back to the app and start the login again." }
  109. }
  110. if (askEmail) {
  111. h1 { "Sign in" }
  112. 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." }
  113. EmailStep {}
  114. }
  115. if (askCode) {
  116. h1 { "Enter your code" }
  117. CodeStep { sentTo = sentTo tail = ". It is valid for 10 minutes." }
  118. }
  119. if (signedIn) {
  120. if (editing) {
  121. IdentityForm { editHeading = editHeading welcome = welcome editId = editId welcomeId = welcomeId fIdentityName = fIdentityName fNickname = fNickname fFirstname = fFirstname fLastname = fLastname fAvatar = fAvatar hasAvatarPreview = hasAvatarPreview }
  122. }
  123. if (choosing) {
  124. ChooseIdentity { rid = rid appName = appName identities = identities }
  125. }
  126. if (manage) {
  127. IdentityList { identities = identities }
  128. TimeZone { timeZone = timeZone }
  129. }
  130. }
  131. p { id = "notice" class = "notice" notice }
  132. p { id = "message" class = "message" message }
  133. }
  134. }
  135. // a placed component shows its answer here (the #message and #notice lines under the card)
  136. status = (String text, String note) => {
  137. message = text
  138. notice = note
  139. }
  140. // 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.
  141. // THE SESSION REMEMBERS THE STEP, then the browser goes to the code page. A function route gets no session (hybriel#11), so the
  142. // face records it; it refuses unless a code for the address is really waiting.
  143. emailSent = (String address) => {
  144. k = emit server rememberPending(address)
  145. if (k == null) {
  146. message = 'the server did not answer — try again'
  147. return null
  148. }
  149. if (k.error != null) {
  150. message = k.error
  151. return null
  152. }
  153. navigate(codeUrl)
  154. }
  155. // the code step (components/codestep.hl) checked the code: why not, or the signed-in account
  156. codeFailed = (String text) => { message = text }
  157. codeVerified = (r) => {
  158. askCode = false
  159. // signed in: the address bar leaves the code page (a reload of /code would go back
  160. // to it anyway — lib/api.hl codePage sends a signed-in browser there)
  161. window.history.replaceState(null, '', homeUrl)
  162. meEmail = r.account.email
  163. timeZone = r.account.timeZone
  164. identities = r.identities
  165. signedIn = true
  166. notice = ''
  167. manage = !forApp
  168. choosing = forApp
  169. // the shell (components/main.hl) shows the user menu from the account: a page's emit reaches every level above it
  170. // (hybriel#193), so the header follows the in-place sign-in without a reload — the welcome form below stays in place
  171. emit shellSession(r.account.email)
  172. // THE FIRST LOGIN: the default identity's names, optional (for an app too: the
  173. // choice follows once the form is saved or skipped)
  174. if (r.created) {
  175. fillForm(r.identities[0])
  176. editHeading = 'Welcome — name your default identity'
  177. welcome = true
  178. editing = true
  179. choosing = false
  180. }
  181. }
  182. // THE IDENTITY FORM (components/identityform.hl) is opened with the values to start from; what the user types is handed up by setF
  183. fillForm = (row) => {
  184. editId = row.id
  185. fIdentityName = row.identityName
  186. fNickname = row.nickname
  187. fFirstname = row.firstname
  188. fLastname = row.lastname
  189. fAvatar = row.avatar
  190. hasAvatarPreview = row.hasAvatar
  191. return null
  192. }
  193. rowOf = (id) => {
  194. for (row of identities) { if ('' + row.id == '' + id) { return row } }
  195. return null
  196. }
  197. openNew = () => {
  198. message = ''
  199. notice = ''
  200. editId = ''
  201. fIdentityName = ''
  202. fNickname = ''
  203. fFirstname = ''
  204. fLastname = ''
  205. fAvatar = ''
  206. hasAvatarPreview = false
  207. editHeading = 'New identity'
  208. welcome = false
  209. editing = true
  210. }
  211. openEdit = (id) => {
  212. message = ''
  213. notice = ''
  214. row = rowOf(id)
  215. if (row == null) { return null }
  216. fillForm(row)
  217. editHeading = 'Edit ' + row.label
  218. welcome = false
  219. editing = true
  220. }
  221. setF = (String name, String v) => {
  222. if (name == 'identityName') { fIdentityName = v }
  223. if (name == 'nickname') { fNickname = v }
  224. if (name == 'firstname') { fFirstname = v }
  225. if (name == 'lastname') { fLastname = v }
  226. if (name == 'avatar') { fAvatar = v hasAvatarPreview = v.trim() != '' }
  227. }
  228. closeForm = () => {
  229. editing = false
  230. welcome = false
  231. message = ''
  232. choosing = forApp
  233. }
  234. formSaved = (rows, String text) => {
  235. identities = rows
  236. notice = text
  237. editing = false
  238. welcome = false
  239. choosing = forApp
  240. }
  241. // the identity list (components/identitylist.hl) deleted an identity
  242. identitiesDeleted = (rows, String id) => {
  243. identities = rows
  244. if ('' + editId == id) { editing = false }
  245. notice = 'Identity deleted.'
  246. }
  247. // the time zone component (components/timezone.hl) saved the account's zone
  248. zoneSaved = (String zone) => {
  249. timeZone = zone
  250. notice = 'Time zone saved.'
  251. }
  252. // "Other address": the session forgets the pending sign-in, back to the email form
  253. back = () => {
  254. message = ''
  255. r = emit server forgetPending()
  256. navigate(homeUrl)
  257. }
  258. // ---- the faces ------------------------------------------------------------------------
  259. // A face's LAST parameter is the session (the framework appends it). Every face that
  260. // needs the account asks accountOfSession, which only accepts the framework's Session.
  261. // A face runs on a BLANK instance: it has its arguments and its imports, not this
  262. // component's members or functions.
  263. // (the code request is NOT a face since mission 010: POST /api/code in lib/api.hl — a face
  264. // sees no request headers, so it could not apply the per-IP limit; a face here would be a
  265. // way around it)
  266. // THE PENDING SIGN-IN (ident#20): recorded after POST /api/code answered, only while a
  267. // code for that address is really waiting (lib/login.hl recordPending); "Other address"
  268. // forgets it. Named apart from the store functions (faces dispatch by name, hybriel#36).
  269. on server rememberPending(email, session) {
  270. return recordPending(&session, email)
  271. }
  272. on server forgetPending(session) {
  273. return dropPending(&session)
  274. }

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