gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit51e387f251e387f2|||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)mre51e387f2/components/embed.hl

5.0 KB

  1. // components/embed.hl — `/embed/signin?key=<api key>&return=<url>` (ident#31): THE SELECTOR'S SIGN-IN, shown inside the selector's
  2. // panel on an app's page (an iframe; lib/api.hl embedSignin checks key + return, parks the request like the login button and allows
  3. // framing only by the app's registered origins). Signed out of ident: email → code → the identity list, all in this frame, with one
  4. // 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
  5. // target="_top": the whole app page then goes to `<return>?ident_code=<code>` (lib/api.hl embedGo), the flow every app handles.
  6. // A new address (the account is created by the first right code) is sent on to ident in the same tab (`/signin/<rid>/welcome`)
  7. // to name its identity and pick it; ident then sends the browser back to the page it came from.
  8. parent './embedshell.hl'
  9. import { accountOfSession } from '../lib/accounts.hl'
  10. import CodeStep from './codestep.hl'
  11. import { identityRows } from '../lib/identities.hl'
  12. import { requestOf } from '../lib/apps.hl'
  13. session = null
  14. rid = null
  15. me = accountOfSession(&session)
  16. request = rid != null ? requestOf(rid) : null
  17. appName = request != null ? request.app.name : ''
  18. identities = me != null ? identityRows(me.id) : []
  19. // the steps (a View's `if` takes a member): email → code → choose (or `fresh` for a new address)
  20. askEmail = me == null
  21. askCode = false
  22. choose = me != null
  23. fresh = false
  24. email = ''
  25. sentTo = ''
  26. message = ''
  27. rowsOf = (list) => {
  28. out = []
  29. for (row of list) { out.push({ label = row.label shortId = row.shortId href = '/embed/go?rid=' + rid + '&identity=' + row.id }) }
  30. return out
  31. }
  32. choices = rowsOf(identities)
  33. newHref = '/signin/' + rid + '/welcome'
  34. View {
  35. embedCard {
  36. if (askEmail) {
  37. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  38. p { id = "embednote" class = "lead" "This signs you in to ident. We mail you a one-time code." }
  39. form { id = "emailform"
  40. on submit(e) {
  41. e.preventDefault()
  42. emit ask(e)
  43. }
  44. label { "Email"
  45. input { id = "email" name = "email" type = "email" autocomplete = "email" required = "required" value = email on input(e) { emit setEmail(e.target.value) } }
  46. }
  47. button { id = "sendcode" type = "submit" "Send me a code" }
  48. }
  49. }
  50. if (askCode) {
  51. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  52. CodeStep { sentTo = sentTo tail = '.' }
  53. }
  54. if (choose) {
  55. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  56. p { class = "lead" "You are signed in to ident. Choose the identity to log in to " strong { appName } " with." }
  57. ul { id = "chooselist"
  58. for (row of choices) {
  59. li { class = "choice"
  60. a { class = "choose" target = "_top" href = row.href
  61. identityMain { identityLabel { row.label } identityShortId { class = "shortid" row.shortId } }
  62. }
  63. }
  64. }
  65. }
  66. }
  67. if (fresh) {
  68. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  69. p { id = "freshnote" class = "lead" "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." }
  70. a { id = "gonew" class = "button" target = "_top" href = newHref "Create my identity" }
  71. }
  72. p { id = "message" class = "message" message }
  73. }
  74. }
  75. // 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
  76. // fitMark whose CSS animation starts when the step appears (and repeats each second for a resize or a message): then the page's content
  77. // height goes to the parent window. No JavaScript of ours; selector.js accepts it from ident's origin only.
  78. on fit(e) {
  79. // the card's bottom edge, not the document's height (the document is as tall as the frame, so it could never shrink)
  80. card = document.querySelector('embed-card')
  81. if (card != null) { window.parent.postMessage({ identFrameHeight = Math.ceil(card.getBoundingClientRect().bottom + window.scrollY) }, '*') }
  82. }
  83. on setEmail(v) { email = v }
  84. // the code request is the same plain POST as on the login page: only an HTTP request carries the client IP the per-IP limit counts
  85. on ask(e) {
  86. message = ''
  87. res = fetch('/api/code', { method = 'POST' headers = { 'Content-Type' = 'application/json' } body = JSON.stringify({ email = email }) })
  88. r = res != null ? res.json() : null
  89. if (r == null) {
  90. message = 'the server did not answer — try again'
  91. return null
  92. }
  93. if (r.error != null) {
  94. message = r.error
  95. return null
  96. }
  97. sentTo = r.email
  98. askEmail = false
  99. askCode = true
  100. }
  101. // the code step (components/codestep.hl) checked the code: the answer, or why not
  102. codeFailed = (String text) => { message = text }
  103. codeVerified = (r) => {
  104. askCode = false
  105. identities = r.identities
  106. choices = rowsOf(r.identities)
  107. if (r.created) {
  108. fresh = true
  109. } else {
  110. choose = true
  111. }
  112. }
  113. back = () => {
  114. message = ''
  115. askCode = false
  116. askEmail = true
  117. }

Branches

Latest commits

  • 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
  • 9b94aa6aMerge branch 'f1b-cleanup' into mainIdent
  • edcfce3f|||PR ident#41 ident#43 ident#44 login error page as a component (same status codes and text, pixel-identical), declarations and route wiring cleaned upmre
  • 3ac85995ident#43 ident#44: plain declarations for never-reassigned lets, one envString helper, named route functions and audience rule out of project.hlmre
  • c7eef14aMerge branch 'nv1-navigate' into mainIdent
  • 644f9775|||PR ident#36 navigate() instead of window.location in the shell, start shell and homemre
  • 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
  • 23971fb7ident#49: media queries in the language's @media formmre
  • 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
  • aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
  • ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
  • dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
  • d277633cident#27: README: identity access and the introspect endpointmre
  • e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
  • 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
  • a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
  • d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre