feat(backend): DB sessions, login modes, single-session rules

Platform v2 step 1.6 (APPS_PLATFORM D-8, D-9, §6.2, §6.4).
- sessions table (revision 0006); every JWT carries `sid` and is accepted
  only while its session is active (validated per request, 10 s cache that
  is dropped the moment a session ends); the in-memory blacklist is gone, so
  logout and "end session" survive restarts
- one login path, POST /api/auth/login {client, username?, user_id?, pin?,
  password?}: manager mode password|pin (username-only "none" removed, D-8),
  waiter mode pin|password|tap (tap answers auth.mode_needs_device until
  paired devices exist), optional "waiter must type username", and the app's
  access key (core.dashboard.access / waiter_app.access)
- auth.single_session_manager / _waiter: off | refuse_new | end_old
- /login without `client` = the current manager UI with v1 rules (pin or
  password; refuse_new treated as end_old because its lock screen re-logs-in);
  /login-by-id is a deprecated wrapper for the current waiter app;
  /login-no-auth removed
- GET /api/auth/sessions, POST /api/auth/sessions/{id}/end (core.staff.manage);
  blocking a user ends their sessions; refresh keeps the session; logout
  takes the bearer header (or ?token= as before)
- settings API validates enum/bool/int values from the manifests;
  security.login_method migrated to auth.manager_login_mode
- tests: modes, single-session rules, logout, refresh, forged token without
  session, manager session list/end

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 19:13:00 +02:00
co-authored by Claude Opus 5.5
parent 3ede13e04a
commit 9f1e12156e
16 changed files with 609 additions and 95 deletions
+3 -1
View File
@@ -3,7 +3,9 @@ from schemas.user import UserOut
class LoginRequest(BaseModel):
username: str
client: str | None = None # "manager" | "waiter"; None = the current manager UI (v1 rules)
username: str | None = None
user_id: int | None = None # waiter picks their name (when the username isn't required)
pin: str | None = None
password: str | None = None