feat(backend,waiter,terminal,manager): sign-in: ask before signing a waiter's other phone out, usernames on paired screens
- auth.single_session_waiter gains 'ask', the new default (Alembic 0051 moves venues on 'off'
to it): a second phone gets auth.session_elsewhere {device, since}; Continue retries with
replace=true and the first phone is signed out at once (live session.ended, reason
"replaced") and says why on its sign-in page. Only phones count (terminal sessions are
their own client). refuse_new / end_old unchanged.
- auth.session_ended now carries the reason; the waiter app keeps it until the next sign-in.
- The waiter app sends queued offline ops on every (re)connection, so an order queued on a
phone that was signed out by another goes out after the next sign-in there (e2e checked).
- auth.terminal_require_username (venue) + Device.require_username (per device, wins):
GET /api/devices/me/users lists nobody, the screen asks for a username then PIN/password,
a picked user_id is refused (auth.username_required), "tap" falls back to PIN.
- Manager: Sign-in settings (ask, the new switch), the device dialog's usernames choice.
Plan platform-v2 6F.7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,7 +44,7 @@ def _check_secret(user, pin, password, db) -> bool:
|
||||
|
||||
|
||||
def do_login(db: Session, request: Request, *, client: str, username: str | None, user_id: int | None,
|
||||
pin: str | None, password: str | None) -> TokenResponse:
|
||||
pin: str | None, password: str | None, replace: bool = False) -> TokenResponse:
|
||||
"""The one login path. Applies the client's login mode, its access key and the
|
||||
single-session rule, then creates a session (core/sessions.py)."""
|
||||
if client not in ("manager", "waiter", "terminal"):
|
||||
@@ -81,7 +81,7 @@ def do_login(db: Session, request: Request, *, client: str, username: str | None
|
||||
if not holds(user, needed):
|
||||
raise XeniaError("auth.client_not_allowed", client=client)
|
||||
|
||||
row = sessions.start(db, user, client, request)
|
||||
row = sessions.start(db, user, client, request, replace=replace)
|
||||
return TokenResponse(access_token=make_token(user, row.id), user=UserOut.model_validate(user))
|
||||
|
||||
|
||||
@@ -104,6 +104,10 @@ def _terminal_login(db: Session, request: Request, *, username, user_id, pin, pa
|
||||
raise XeniaError("auth.login_mode_not_allowed", mode="password")
|
||||
if mode == "password" and not password:
|
||||
raise XeniaError("auth.login_mode_not_allowed", mode="pin")
|
||||
if sessions.terminal_requires_username(db, device):
|
||||
if not username:
|
||||
raise XeniaError("auth.username_required")
|
||||
user_id = None # usernames only: a picked id isn't enough (6F.7)
|
||||
|
||||
q = db.query(User).filter(User.is_active == True) # noqa: E712
|
||||
user = q.filter(User.username == username).first() if username else (
|
||||
@@ -122,7 +126,7 @@ def login(body: LoginRequest, request: Request, db: Session = Depends(get_db)):
|
||||
"""POST {client: "manager"|"waiter"|"terminal", username?, user_id?, pin?, password?}.
|
||||
"terminal" = a user on a paired device: send the X-Xenia-Device header."""
|
||||
return do_login(db, request, client=body.client, username=body.username,
|
||||
user_id=body.user_id, pin=body.pin, password=body.password)
|
||||
user_id=body.user_id, pin=body.pin, password=body.password, replace=body.replace)
|
||||
|
||||
|
||||
@router.post("/refresh", response_model=TokenResponse)
|
||||
|
||||
Reference in New Issue
Block a user