gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain0f6d1592Merge branch 'f18b-shell-session' into mainIdentmain/components/codestep.hl

2.5 KB

  1. // 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)
  2. // 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);
  3. // this component owns the code field, the browser's time zone and the check against the server (face verifyCode, lib/login.hl
  4. // signInWithCode). What follows is the host's: it gets the answer through $parent.codeVerified(r) or $parent.codeFailed(text), and
  5. // "Other address" is $parent.back(). Markup, ids and look are those both pages had before (the CSS is components/styles.hl).
  6. import { signInWithCode } from '../lib/login.hl'
  7. import { leadLook } from './styles.hl'
  8. sentTo = ''
  9. tail = '.'
  10. code = ''
  11. Style {
  12. pLead = leadLook
  13. '#code' {
  14. fontSize = '1.4rem'
  15. letterSpacing = '.3em'
  16. fontVariantNumeric = 'tabular-nums'
  17. }
  18. }
  19. View {
  20. p { id = "sentto" Style.pLead "We sent a six-digit code to " strong { sentTo } tail }
  21. form { id = "codeform"
  22. on submit(e) {
  23. e.preventDefault()
  24. emit verify(e)
  25. }
  26. label { "One-time code"
  27. 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) } }
  28. }
  29. formButtons {
  30. button { id = "verify" type = "submit" "Sign in" }
  31. button { id = "back" type = "button" class = "quiet" "Other address" on click(e) { $parent.back() } }
  32. }
  33. }
  34. }
  35. on setCode(v) { code = v }
  36. // the browser's own time zone (IANA name) goes with the first login (`Intl` is a browser global of client code, hybriel#18)
  37. browserZone = () => { return Intl.DateTimeFormat().resolvedOptions().timeZone }
  38. on verify(e) {
  39. $parent.codeFailed('')
  40. r = emit server verifyCode(sentTo, code, browserZone())
  41. if (r == null) {
  42. $parent.codeFailed('the server did not answer — try again')
  43. return null
  44. }
  45. if (r.error != null) {
  46. $parent.codeFailed(r.error)
  47. return null
  48. }
  49. $parent.codeVerified(r)
  50. }
  51. // the right code signs the session in; the first one for an address creates the account, its default identity and stores the
  52. // browser's time zone
  53. on server verifyCode(email, code, timeZone, session) {
  54. if (session == null) { return { error = 'no session — reload the page' } }
  55. if (email == null || hlTypeName(email) != 'String' || code == null || hlTypeName(code) != 'String') { return { error = 'email and code must be strings' } }
  56. return signInWithCode(&session, email, code, timeZone)
  57. }

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