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>
28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
"""Login sessions (APPS_PLATFORM D-9, §6.2).
|
|
|
|
One row per login. The JWT carries the row id as `sid`; a request is accepted only while
|
|
its session is active (ended_at NULL). This makes logout real, survives restarts, lets
|
|
managers see and end sessions, and enforces the one-session-per-user rules.
|
|
Read and written through core/sessions.py only.
|
|
"""
|
|
from sqlalchemy import Column, ForeignKey, Integer, String
|
|
|
|
from core.timeutil import UTCDateTime, utcnow
|
|
from database import Base
|
|
|
|
|
|
class LoginSession(Base):
|
|
__tablename__ = "sessions"
|
|
|
|
id = Column(String, primary_key=True) # uuid4 hex
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=True, index=True)
|
|
# NULL user_id = the support account (synthetic, no users row; step 1.10)
|
|
device_id = Column(Integer, nullable=True) # step 1.8
|
|
client = Column(String, nullable=False) # manager | waiter | terminal | support
|
|
created_at = Column(UTCDateTime, nullable=False, default=utcnow)
|
|
last_seen_at = Column(UTCDateTime, nullable=False, default=utcnow)
|
|
ended_at = Column(UTCDateTime, nullable=True, index=True)
|
|
end_reason = Column(String, nullable=True) # logout | replaced | ended_by_manager | user_blocked | refreshed
|
|
ip = Column(String, nullable=True)
|
|
user_agent = Column(String, nullable=True)
|