gitoria

ident

All repositories: gitoria

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

2.5 KB

  1. // components/chooseidentity.hl — THE APP'S IDENTITY CHOICE (ident#40.3), placed by components/home.hl on `/signin/<rid>`: which identity
  2. // signs in to the app that sent the browser here. The host passes in the login request (rid), the app's name and the rows (identities).
  3. // A click asks the server for the app's return URL with a one-time code (face chooseIdentity, lib/apps.hl grantRequest: a plain
  4. // login, or an invite's) and the browser goes there. The host shows the messages: $parent.status(message, notice).
  5. import { navigate } from 'hl:web'
  6. import { accountOfSession } from '../lib/accounts.hl'
  7. import { grantRequest } from '../lib/apps.hl'
  8. import { leadLook, avatarLook } from './styles.hl'
  9. rid = null
  10. appName = ''
  11. identities = []
  12. Style {
  13. pLead = leadLook
  14. pAvatar = avatarLook
  15. '#chooselist img' {
  16. width = '32px'
  17. height = '32px'
  18. }
  19. }
  20. View {
  21. section { id = "choosesection"
  22. h1 { "Choose an identity" }
  23. p { Style.pLead "Which identity signs in to " strong { appName } "? The app gets only the identity's short id — no email, no names." }
  24. ul { id = "chooselist"
  25. for (row of identities) {
  26. li {
  27. if (row.hasAvatar) { img { Style.pAvatar src = row.avatar alt = "" width = "32" height = "32" } }
  28. identityMain {
  29. identityLabel { row.label }
  30. identityShortId { row.shortId }
  31. if (row.isDefault) { defaultBadge { "default" } }
  32. identityDetails { row.details }
  33. }
  34. button { type = "button" class = "choose" value = row.id "Continue" on click(e) { emit choose(e.target.value) } }
  35. }
  36. }
  37. }
  38. }
  39. }
  40. // THE CHOICE: the server makes (or finds) this identity's id for the app and answers
  41. // the app's return URL with a one-time code — the browser goes there
  42. on choose(id) {
  43. $parent.status('', '')
  44. r = emit server chooseIdentity(rid, '' + id)
  45. if (r == null) {
  46. $parent.status('the server did not answer — try again', '')
  47. return null
  48. }
  49. if (r.error != null) {
  50. $parent.status(r.error, '')
  51. return null
  52. }
  53. $parent.status('', 'Back to ' + appName + ' …')
  54. navigate(r.url, replace = true)
  55. }
  56. // the identity for the app's login request (lib/apps.hl grantRequest): { url } or { error }
  57. on server chooseIdentity(rid, identity, session) {
  58. let me = accountOfSession(&session)
  59. if (me == null) { return { error = 'you are not signed in' } }
  60. if (rid == null || hlTypeName(rid) != 'String') { return { error = 'field rid must be a string' } }
  61. if (identity == null || hlTypeName(identity) != 'String') { return { error = 'field identity must be a string' } }
  62. return grantRequest(me.id, rid, identity)
  63. }

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