gitoria

ident

All repositories: gitoria

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

6.1 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 EmailStep from './emailstep.hl'
  11. import CodeStep from './codestep.hl'
  12. import { identityRows } from '../lib/identities.hl'
  13. import { requestOf } from '../lib/apps.hl'
  14. import { leadLook, messageLook } from './styles.hl'
  15. session = null
  16. rid = null
  17. me = accountOfSession(&session)
  18. request = rid != null ? requestOf(rid) : null
  19. appName = request != null ? request.app.name : ''
  20. identities = me != null ? identityRows(me.id) : []
  21. // the steps (a View's `if` takes a member): email → code → choose (or `fresh` for a new address)
  22. askEmail = me == null
  23. askCode = false
  24. choose = me != null
  25. fresh = false
  26. sentTo = ''
  27. message = ''
  28. rowsOf = (list) => {
  29. out = []
  30. for (row of list) { out.push({ label = row.label shortId = row.shortId href = '/embed/go?rid=' + rid + '&identity=' + row.id }) }
  31. return out
  32. }
  33. choices = rowsOf(identities)
  34. newHref = '/signin/' + rid + '/welcome'
  35. // the selector's sign-in frame (ident#31): inside the selector's panel (same surface colour), the same fields and buttons
  36. Style {
  37. pLead = leadLook
  38. pMessage = messageLook
  39. 'html:has(embed-card), body:has(embed-card)' {
  40. background = 'var(--color-surface)'
  41. }
  42. fitMark {
  43. position = 'absolute'
  44. width = '0'
  45. height = '0'
  46. overflow = 'hidden'
  47. animation = 'ident-frame-fit 1s infinite'
  48. }
  49. '@keyframes ident-frame-fit' = {
  50. 'from' = { opacity = '1' }
  51. to = { opacity = '0.99' }
  52. }
  53. embedCard {
  54. display = 'grid'
  55. gap = '.8rem'
  56. padding = '.5rem'
  57. }
  58. 'embed-card p' {
  59. margin = '0'
  60. overflowWrap = 'anywhere'
  61. }
  62. 'embed-card, embed-card form, embed-card label, embed-card input, embed-card li' {
  63. minWidth = '0'
  64. }
  65. 'embed-card input' {
  66. width = '100%'
  67. maxWidth = '100%'
  68. boxSizing = 'border-box'
  69. }
  70. 'embed-card #code' {
  71. fontSize = '1.2rem'
  72. letterSpacing = '.15em'
  73. }
  74. 'embed-card form' {
  75. display = 'grid'
  76. gap = '.8rem'
  77. }
  78. 'embed-card label' {
  79. display = 'grid'
  80. gap = '.25rem'
  81. marginBottom = '0'
  82. }
  83. 'embed-card .message:empty' {
  84. display = 'none'
  85. }
  86. 'embed-card .lead' {
  87. color = 'var(--color-text-muted)'
  88. }
  89. 'embed-card #chooselist' {
  90. listStyle = 'none'
  91. margin = '0'
  92. padding = '0'
  93. display = 'grid'
  94. gap = '.5rem'
  95. }
  96. 'embed-card #chooselist li' {
  97. background = 'var(--color-background-sunken)'
  98. flexWrap = 'nowrap'
  99. }
  100. 'embed-card identity-main' {
  101. flex = '1 1 auto'
  102. }
  103. 'embed-card #chooselist a' {
  104. display = 'flex'
  105. flex = '1 1 auto'
  106. alignItems = 'center'
  107. minHeight = 'var(--layout-tap)'
  108. color = 'inherit'
  109. textDecoration = 'none'
  110. }
  111. 'embed-card a.button' {
  112. display = 'inline-flex'
  113. alignItems = 'center'
  114. justifyContent = 'center'
  115. minHeight = 'var(--layout-tap)'
  116. textDecoration = 'none'
  117. }
  118. }
  119. View {
  120. embedCard {
  121. if (askEmail) {
  122. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  123. p { id = "embednote" Style.pLead "This signs you in to ident. We mail you a one-time code." }
  124. EmailStep {}
  125. }
  126. if (askCode) {
  127. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  128. CodeStep { sentTo = sentTo tail = '.' }
  129. }
  130. if (choose) {
  131. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  132. p { Style.pLead "You are signed in to ident. Choose the identity to log in to " strong { appName } " with." }
  133. ul { id = "chooselist"
  134. for (row of choices) {
  135. li {
  136. a { class = "choose" target = "_top" href = row.href
  137. identityMain { identityLabel { row.label } identityShortId { row.shortId } }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. if (fresh) {
  144. fitMark { on animationstart(e) { emit fit(e) } on animationiteration(e) { emit fit(e) } }
  145. p { id = "freshnote" Style.pLead "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." }
  146. a { id = "gonew" class = "button" target = "_top" href = newHref "Create my identity" }
  147. }
  148. p { id = "message" Style.pMessage message }
  149. }
  150. }
  151. // 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
  152. // fitMark whose CSS animation starts when the step appears (and repeats each second for a resize or a message): then the page's content
  153. // height goes to the parent window. No JavaScript of ours; selector.js accepts it from ident's origin only.
  154. on fit(e) {
  155. // the card's bottom edge, not the document's height (the document is as tall as the frame, so it could never shrink)
  156. card = document.querySelector('embed-card')
  157. if (card != null) { window.parent.postMessage({ identFrameHeight = Math.ceil(card.getBoundingClientRect().bottom + window.scrollY) }, '*') }
  158. }
  159. // the email step (components/emailstep.hl) asked for a code (the plain POST to /api/code): the frame goes on to the code step
  160. emailSent = (String address) => {
  161. sentTo = address
  162. askEmail = false
  163. askCode = true
  164. }
  165. // the code step (components/codestep.hl) checked the code: the answer, or why not
  166. codeFailed = (String text) => { message = text }
  167. codeVerified = (r) => {
  168. askCode = false
  169. identities = r.identities
  170. choices = rowsOf(r.identities)
  171. if (r.created) {
  172. fresh = true
  173. } else {
  174. choose = true
  175. }
  176. }
  177. back = () => {
  178. message = ''
  179. askCode = false
  180. askEmail = true
  181. }

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