Files
bonaminandClaude Opus 5.5 3a522e457d feat(backend): support access by offline challenge codes replaces the master account
Platform v2 step 1.10 (APPS_PLATFORM D-16, section 6.5).
- POST /api/auth/support/challenge (public): an 8-character challenge, stored 15 min
  (support_challenges, revision 0009; at most 5 open). POST /api/auth/support/verify
  {challenge, code}: code = base32(HMAC(SUPPORT_SECRET, site_id + challenge))[:10];
  single use, 5 wrong codes burn the challenge. Opens a 4 h support session
  (client=support, synthetic superadmin) with a hard end: sessions.expires_at.
- core/support_codes.py (stdlib only) is the derivation; tools/support_code.py
  (--init, --site-secret <SITE_ID>, <SITE_ID> <CHALLENGE>) uses it on the builder's
  machine with the master key in %USERPROFILE%/.xenia/support_master_key.txt.
- MASTER_USERNAME/MASTER_PASSWORD removed (config, login, docker-compose.yml,
  .env.example); SUPPORT_SECRET added; install.sh asks for it.
- e2e: backends get SUPPORT_SECRET from a test master key and log in with challenge
  codes (lib/support.mjs, license_e2e.py); install.mjs expects the new prompt.
- Pack rule CS-15.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 10:52:16 +02:00

29 lines
1.5 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, ForeignKey("devices.id"), nullable=True, index=True) # terminal sessions: the device
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)
expires_at = Column(UTCDateTime, nullable=True) # hard end (support sessions: 4 h); NULL = none
end_reason = Column(String, nullable=True) # logout | replaced | ended_by_manager | user_blocked | refreshed | device_revoked | device_reassigned | expired
ip = Column(String, nullable=True)
user_agent = Column(String, nullable=True)