gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitd69665f6d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmred69665f6/components/home.hl

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

Branches

Latest commits

  • d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmre
  • 3a64dc48ident#34: chipLook: radius as the same var() string (a bare token name in a static does not compile); selector gate selectormre
  • eb039073ident#34: tests: signin and migration find the choice without the classmre
  • 4b94a594ident#34: tests: fix selector of the identity choicemre
  • bebc88e4ident#34: main.hl drops the unstyled classes inboxlink and whomre
  • b4e7ad04ident#34: the identity choice link/button has no class (rule on #chooselist a)mre
  • 3c33d6eaident#34: the connection link in inbox has no class (rule on #conns a)mre
  • dc97ec0dident#34: the Notif. chip and the Used in link share chipLook (Style.pChip) instead of the classes chip/used/notifmre
  • 378bd432ident#34: the identity picture look is a static in styles.hl (Style.pAvatar); sizes stay with each listmre
  • 1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre
  • ddc7d135Merge branch 'f7-hooks' into mainIdent
  • eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
  • ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre