calendar
All repositories: gitoria
3.4 KB
// lib/api.hl — THE FUNCTION ROUTES (calendar mission 001, code order): thin wrappers — check the input and the session,// call the topic (lib/users.hl), answer. The calendar's own reads and writes are faces (components/calendar.hl).//// THE LOGIN BUTTON'S RETURN (ident README "How apps use ident"): /login/callback?ident_code=&next= → the user// (lib/users.hl userOfLoginCode) → the session is signed in → back to `next` (lib/api-helpers.hl safePath). A FAILED// LOGIN is a page (components/loginfailed.hl): the reason is parked in the session, then → /login/failed.// These two write the session: project.hl hands them the request and the session store BY REFERENCE (&req, &sessions);// a by-value copy would lose the write (tickets mission 010, gitoria mission 002, notes mission 002).import { Response } from 'hl:http1'import { randomBytes } from 'hl:crypto'import { userOfLoginCode, usersTable } from './users.hl'import { eventsTable } from './events.hl'import { countOfList } from './util.hl'import { safePath } from './api-helpers.hl'import { tooManyLogins } from './login-limit.hl'static loginFailed = (&req, &sessions, why) => {let s = req.sessionfresh = s == nullif (fresh) { s = sessions.mint() }s.data.loginError = whysessions.save(s)res = new Response('login failed: ' + why, { status = 302 headers = { 'Location' = '/login/failed' 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' 'Referrer-Policy' = 'no-referrer' } })if (fresh) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id) }return res}// the function route gets the cookie's session as req.session (hybriel #11); none yet → minted herestatic loginCallback = (route, &req, &sessions) => {if (req.method != 'GET') { return loginFailed(&req, &sessions, 'GET only') }q = req.query != null ? req.query : {}code = q.ident_codeif (code == null || code == '') { return loginFailed(&req, &sessions, 'ident sent no login code') }// the per-client limit comes before the exchange (which calls ident); nginx sets X-Client-IPif (tooManyLogins(req.headers['x-client-ip'])) { return loginFailed(&req, &sessions, 'too many login attempts from your network — wait a few minutes') }x = userOfLoginCode(code)if (x.error != null) { return loginFailed(&req, &sessions, x.error) }// THE SAME SESSION, NEVER SIGNED OUT (ident#28): a good code signs the session the browser already has in (a second tab or an// installed app may not store a new cookie, and a session we signed out would leave it anonymous); none yet → minted herelet s = req.sessionif (s == null) { s = sessions.mint() }s.user = { id = x.user.id }s.data.tag = randomBytes(16)s.data.loginError = nullsessions.save(s)res = new Response('logged in', { status = 302 headers = { 'Location' = safePath(q.next) 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' 'Referrer-Policy' = 'no-referrer' 'Set-Cookie' = sessions.cookieHeader(s.id) } })return res}// /health: 200 only when both tables answer (they are loaded at start); deploys wait for it (standby-swap.sh) before they switch containersstatic health = () => {let u = countOfList(usersTable.find(null, null))let e = countOfList(eventsTable.find(null, null))return new Response('ok', { status = 200 headers = { 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } })}
Branches
Latest commits
- edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
- bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
- 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
- cc759328Merge sb3-standby: calendar deploys through its standbymre
- f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre
- 229643f7Merge branch 'cal-14'mre
- 1110b26fcalendar#14: the month name no longer breaks into two lines on a phone (Reminder settings drops to its own row when the header is too narrow), gate checks for one-line title and all header controls on screenmre
- 490c658aident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- 18095868calendar: Reminder settings button opens its dialog again (the dialog's open handler still closed the removed user menu and stopped); old e2e and gate scripts use the new headermre
- 6eee4b5acalendar header: the selector alone top right plus Log out as before the theme missions; Reminder settings back on the month page (WIP: the settings test still fails)mre
- 0b909decident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 0c8f9364Merge branch 'sy-sync'mre
- 9fab1c8fsync components.hybriel 4922f9c into the month view: prev / next 44 px targets, names formatted in UTC (a UTC+12 zone showed the wrong first weekday); the calendar keeps its own language handling (Accept-Language / browser) and the P1/C13 reminder code; gate: 44 px check (SY)mre
- 27d3e294theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 2ac9c1bbdeploy: security gate (tests/security.mjs)mre
- 6b0a2571merge sc-sec (calendar security) with 99-year sessionsmre
- 92001e52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 0f76c99dSecurity audit SC: push endpoint SSRF guard, uploadMax 0, Secure cookie, login session rotation + rate limit, event cap, nosniff, security gatemre
- 2dd53dccP1: one reminder shows once: arm() one at a time, the page skips reminders the server already pushed; push-twice gatemre
- 3a29760aC13 report (handoff)mre