A WordPress-inspired CMS whose entire backend is PiCloud Rhai scripts deployed with pic apply, plus a SvelteKit frontend. Built to dogfood the project tool, CLI, and SDK; exercises docs/kv/files/users, docs+queue+cron +pubsub triggers, the transactional-outbox notification chain, a docs before-interceptor, set_if CAS, SSE, per-app CORS, env overlays, and a durable Workflow (validate -> enrich || seo -> publish -> finalize) started with workflow::start and polled with workflow::run_status, visualized live with Svelte Flow. FINDINGS.md / SECURITY.md capture every gap, surprise, and security issue found (each tagged [PiCloud] vs [CMS]); the platform fixes for the actionable ones ship in the preceding commit. Also folds in the read-only `pic` allowlist entries added to .claude/settings.json during the session (fewer-permission-prompts). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
24 lines
969 B
Plaintext
24 lines
969 B
Plaintext
// POST /cms/auth/login — exchange email+password for a session token (public).
|
|
// Guard the body type: since the platform fix (F-026) non-JSON bodies now reach
|
|
// the script (text -> string, binary -> base64), so an endpoint expecting a JSON
|
|
// object must type-check rather than assume a map (else it throws -> 502).
|
|
let b = ctx.request.body;
|
|
if type_of(b) != "map" || b.email == () || b.password == () {
|
|
return #{ statusCode: 400, body: #{ error: "email and password required" } };
|
|
}
|
|
let token = ();
|
|
try { token = users::login(b.email, b.password); } catch(e) { token = (); }
|
|
if token == () {
|
|
return #{ statusCode: 401, body: #{ error: "invalid credentials" } };
|
|
}
|
|
let u = users::verify(token);
|
|
let roles = [];
|
|
for r in ["admin", "author", "reader"] { if users::has_role(u.id, r) { roles.push(r); } }
|
|
#{
|
|
statusCode: 200,
|
|
body: #{
|
|
token: token,
|
|
user: #{ id: u.id, email: u.email, display_name: u.display_name, roles: roles }
|
|
}
|
|
}
|