gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitacb957cfacb957cfcalendar#12: Send a test notification on a subscribed device (one push in ~10 s, owner's own device), push gate part 4mreacb957cf/lib/api.hl

2.2 KB

  1. // lib/api.hl — THE FUNCTION ROUTES (calendar mission 001, code order): thin wrappers — check the input and the session,
  2. // call the topic (lib/users.hl), answer. The calendar's own reads and writes are faces (components/calendar.hl).
  3. //
  4. // THE LOGIN BUTTON'S RETURN (ident README "How apps use ident"): /login/callback?ident_code=&next= → the user
  5. // (lib/users.hl userOfLoginCode) → the session is signed in → back to `next` (lib/api-helpers.hl safePath). A FAILED
  6. // LOGIN is a page (components/loginfailed.hl): the reason is parked in the session, then → /login/failed.
  7. // These two write the session: project.hl hands them the request and the session store BY REFERENCE (&req, &sessions);
  8. // a by-value copy would lose the write (tickets mission 010, gitoria mission 002, notes mission 002).
  9. import { Response } from 'hl:http1'
  10. import { randomBytes } from 'hl:crypto'
  11. import { userOfLoginCode } from './users.hl'
  12. import { safePath } from './api-helpers.hl'
  13. static loginFailed = (&req, &sessions, why) => {
  14. let s = req.session
  15. fresh = s == null
  16. if (fresh) { s = sessions.mint() }
  17. s.data.loginError = why
  18. sessions.save(s)
  19. res = new Response('login failed: ' + why, { status = 302 headers = { 'Location' = '/login/failed' 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' } })
  20. if (fresh) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id) }
  21. return res
  22. }
  23. // the function route gets the cookie's session as req.session (hybriel #11); none yet → minted here
  24. static loginCallback = (route, &req, &sessions) => {
  25. if (req.method != 'GET') { return loginFailed(&req, &sessions, 'GET only') }
  26. q = req.query != null ? req.query : {}
  27. code = q.ident_code
  28. if (code == null || code == '') { return loginFailed(&req, &sessions, 'ident sent no login code') }
  29. x = userOfLoginCode(code)
  30. if (x.error != null) { return loginFailed(&req, &sessions, x.error) }
  31. let s = req.session
  32. fresh = s == null
  33. if (fresh) { s = sessions.mint() }
  34. s.user = { id = x.user.id }
  35. s.data.tag = randomBytes(16)
  36. s.data.loginError = null
  37. sessions.save(s)
  38. res = new Response('logged in', { status = 302 headers = { 'Location' = safePath(q.next) 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' } })
  39. if (fresh) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id) }
  40. return res
  41. }

Branches

Latest commits

  • acb957cfcalendar#12: Send a test notification on a subscribed device (one push in ~10 s, owner's own device), push gate part 4mre
  • 0b222eb8tests: e2e-theme CDP port default from E2E_THEME_CDP_PORT (8756 unchanged)mre
  • 8b8a5abare-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • a69b27f9docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 1a97edfdcalendar mission 010: reminder rows at 390 px (the 7-column month grid no longer catches the reminder lists), gate checks, settings-shots, reportmre
  • 61b21404calendar mission 009: reminder times on hl:time in the browser (lib/push-plan.hl and the Intl code removed), DST gate tests/dst.mjs, E2E script, reportmre
  • 875353c1calendar mission 009: re-vendor Hybriel master 022a3ac1 (int 6 6b396322 hl:time browser side, int 7 65e8ec21; bin sha256 6e0f77d7, plugins whole)mre
  • ce16a4efdeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • f490bc8cdeploy: Web Push gate tests/push.mjs (PUSH_GATE_PORT)mre
  • 3af29fc8calendar mission 008 (A8): report, README, LOG, push-shots.mjsmre
  • f91f3663calendar mission 008 (A8): push only asked of the browser when the app has the VAPID settings (pushAvailable); real-FCM E2E scripts (push-real-app.mjs, push-real.mjs)mre
  • bf571badcalendar mission 008 (A8): Turn off on this device (unsubscribes the browser, server drops the device, choice kept), subscribe/refresh when the app is shown again; push gate part 3mre
  • 50985708calendar mission 008 (A7): Web Push report, README, mission, LOGmre
  • ee318774calendar mission 008 (A7): push-real.mjs, push sent log linemre
  • ebda0fd1calendar mission 008 (A7): server-side reminder plan on hl:time (push-plan.hl; hl:time fromLocal in a browser static is refused: repro .scratch/hltime-client), push gate 9/9mre
  • d063dad3calendar mission 008 (A7): Web Push (WIP): lib/push.hl subscriptions + sender clock, faces calPushSave/calPushOff, button subscribes, VAPID tool, tests/push.mjs; instantOf on hl:timemre
  • cf175c80calendar mission 008 (A7): re-vendor Hybriel master 0e3c9830 (bin 9d957fed, plugins whole: hl:crypto Web Push primitives, hl:web sendPush)mre
  • 9bf3c38bcalendar mission 008: re-vendor Hybriel f9833544 (gates old = new); Web Push stopped: hl:crypto half missing on mastermre
  • 186f969bcalendar mission 007: signed-in gate for the first-pointer race (fails on 3c5604f), README theme section, reportmre
  • ba9b4955calendar mission 006: first pointer event no longer re-runs the month (stale overwrite race), gate check, e2e settings cleanup, reportmre