feat(manager): v2 sign-in (login modes, support access, license notice) and an unlock endpoint for the lock screen

Platform-v2 step 2.6b:
- backend: POST /api/auth/unlock {pin|password} checks the CURRENT session's
  user and keeps the session (no new login/token); 5 wrong tries end it
  (auth.wrong_pin with attempts_left, then auth.session_ended); bootstrap
  gains `login` (manager_mode, autofill_username, support)
- manager LoginPage rewritten on @xenia/ui + i18n: client "manager", password
  or PIN pad per setting, remembered/only account card, support access panel
  (challenge -> code -> 4 h session, not remembered as an account), notice
  when the license runs the free tier (expired/inactive/locked/clock/unverified)
- lock screen on /api/auth/unlock with the shared PinPad
- @xenia/ui PinPad: variable length (minLength/maxLength, OK key, Enter)
- e2e manager.mjs: 33 checks (+ lockout after 5 wrong PINs, PIN login mode,
  support access with a wrong then right code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 22:17:09 +02:00
co-authored by Claude Opus 5.5
parent df57fd1552
commit 49a412d748
22 changed files with 574 additions and 475 deletions
+40
View File
@@ -3,6 +3,7 @@ from core.access.check import holds
from core.access.queries import holders_filter
import bcrypt
import logging
import threading
from typing import Optional
import jwt
@@ -143,6 +144,45 @@ def refresh(credentials: HTTPAuthorizationCredentials = Depends(bearer), db: Ses
return TokenResponse(access_token=make_token(user, payload["sid"]), user=UserOut.model_validate(user))
# ── Unlock (plan step 2.6b) ──────────────────────────────────────────────────
# The manager's lock screen (and later the apps' own) checks the PIN of the user who owns
# the CURRENT session, and keeps that session: no new login, no new token, so the
# single-session rules never see a second login. After UNLOCK_MAX_FAILURES wrong tries
# the session is ended (someone is guessing on an unattended screen).
UNLOCK_MAX_FAILURES = 5
_unlock_failures: dict[str, int] = {} # sid -> wrong tries since the last success
_unlock_lock = threading.Lock()
class UnlockRequest(_PydanticBase):
pin: Optional[str] = None
password: Optional[str] = None
@router.post("/unlock")
def unlock(body: UnlockRequest, request: Request, db: Session = Depends(get_db),
user: User = Depends(get_current_user)):
"""POST {pin} (or {password}) with the session's own token. 200 {user} = unlocked.
Wrong: 401 auth.wrong_pin {attempts_left}; the last allowed miss ends the session
(401 auth.session_ended)."""
sid = getattr(request.state, "xenia_sid", None)
if _check_secret(user, body.pin, body.password, db):
with _unlock_lock:
_unlock_failures.pop(sid, None)
return {"user": UserOut.model_validate(user)}
with _unlock_lock:
failures = _unlock_failures.get(sid, 0) + 1
_unlock_failures[sid] = failures
if failures >= UNLOCK_MAX_FAILURES:
with _unlock_lock:
_unlock_failures.pop(sid, None)
sessions.end(db, sid, "unlock_failed")
_logger.warning("auth.unlock: too many wrong PINs, session ended user=%s", user.id)
raise XeniaError("auth.session_ended")
raise XeniaError("auth.wrong_pin", attempts_left=UNLOCK_MAX_FAILURES - failures)
@router.post("/logout", dependencies=[Depends(public())])
def logout(credentials: Optional[HTTPAuthorizationCredentials] = Depends(_optional_bearer),
token: Optional[str] = None, db: Session = Depends(get_db)):