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
+1
View File
@@ -48,6 +48,7 @@ export function AccessProvider({
venue: d.venue,
user: d.user,
license: d.license,
login: d.login,
languages: d.languages,
language: d.language,
modules: new Set((d.modules || []).map(m => m.key)),
+2 -1
View File
@@ -31,7 +31,8 @@
"moreInfo": "Περισσότερες πληροφορίες",
"notifications": "Ειδοποιήσεις",
"backspace": "Διαγραφή",
"pinProgress": "{{count}} από {{total}} ψηφία"
"pinProgress": "{{count}} από {{total}} ψηφία",
"submit": "OK"
},
"override": {
"title": "Έγκριση υπευθύνου",
+2 -1
View File
@@ -35,7 +35,8 @@
"session_not_found": "Η σύνδεση δεν βρέθηκε.",
"support_not_configured": "Η πρόσβαση υποστήριξης δεν έχει ρυθμιστεί σε αυτό το κατάστημα.",
"support_code_invalid": "Ο κωδικός υποστήριξης είναι λάθος ή έχει λήξει. Ζητήστε νέο κωδικό πρόκλησης.",
"support_rate_limited": "Πολλές αιτήσεις υποστήριξης. Περιμένετε λίγα λεπτά και δοκιμάστε ξανά."
"support_rate_limited": "Πολλές αιτήσεις υποστήριξης. Περιμένετε λίγα λεπτά και δοκιμάστε ξανά.",
"wrong_pin": "Λάθος PIN. Απομένουν {{attempts_left}} προσπάθειες πριν αποσυνδεθείτε."
},
"device": {
"revoked": "Αυτή η συσκευή αφαιρέθηκε. Κάντε ξανά σύζευξη.",
+31
View File
@@ -46,5 +46,36 @@
"edit": "Επεξεργασία προφίλ",
"signOut": "Αποσύνδεση",
"language": "Γλώσσα"
},
"login": {
"title": "Σύνδεση",
"subtitle": "Πίνακας διαχείρισης",
"username": "Όνομα χρήστη",
"password": "Κωδικός",
"pin": "PIN",
"signIn": "Σύνδεση",
"otherAccount": "Άλλος λογαριασμός",
"supportLink": "Πρόσβαση υποστήριξης"
},
"support": {
"title": "Πρόσβαση υποστήριξης",
"intro": "Διαβάστε αυτόν τον κωδικό στην υποστήριξη της Xenia. Θα σας δώσουν έναν κωδικό πίσω.",
"challenge": "Κωδικός για την υποστήριξη",
"answer": "Κωδικός της υποστήριξης",
"verify": "Άνοιγμα συνεδρίας υποστήριξης",
"newChallenge": "Νέος κωδικός",
"back": "Πίσω στη σύνδεση",
"expires": "Ο κωδικός ισχύει μέχρι τις {{time}}."
},
"license": {
"expired": "Η άδεια έχει λήξει. Το κατάστημα λειτουργεί με τη δωρεάν έκδοση μέχρι την ανανέωση: κάποιες λειτουργίες είναι κλειστές.",
"inactive": "Η άδεια δεν είναι ενεργή. Το κατάστημα λειτουργεί με τη δωρεάν έκδοση: κάποιες λειτουργίες είναι κλειστές.",
"locked": "Ο πάροχος κλείδωσε την άδεια του καταστήματος. Λειτουργεί με τη δωρεάν έκδοση: κάποιες λειτουργίες είναι κλειστές.",
"clock": "Το ρολόι του server γύρισε πίσω, οπότε η άδεια δεν μπορεί να ελεγχθεί. Διορθώστε την ημερομηνία και ώρα του server ή συνδέστε τον στο internet.",
"unverified": "Η άδεια δεν έχει ελεγχθεί ακόμα (δεν υπάρχει σύνδεση με τον server αδειών). Προς το παρόν λειτουργεί η δωρεάν έκδοση."
},
"lock": {
"title": "Κλειδωμένο",
"signOutInstead": "Αποσύνδεση"
}
}
+2 -1
View File
@@ -31,7 +31,8 @@
"moreInfo": "More info",
"notifications": "Notifications",
"backspace": "Delete",
"pinProgress": "{{count}} of {{total}} digits entered"
"pinProgress": "{{count}} of {{total}} digits entered",
"submit": "OK"
},
"override": {
"title": "Manager approval",
+2 -1
View File
@@ -35,7 +35,8 @@
"session_not_found": "Session not found.",
"support_not_configured": "Support access isn't set up on this site.",
"support_code_invalid": "That support code is wrong or has expired. Ask for a new challenge.",
"support_rate_limited": "Too many support challenges. Wait a few minutes and try again."
"support_rate_limited": "Too many support challenges. Wait a few minutes and try again.",
"wrong_pin": "Wrong PIN. {{attempts_left}} tries left before you are signed out."
},
"device": {
"revoked": "This device was removed. Pair it again.",
+31
View File
@@ -46,5 +46,36 @@
"edit": "Edit profile",
"signOut": "Sign out",
"language": "Language"
},
"login": {
"title": "Sign in",
"subtitle": "Manager dashboard",
"username": "Username",
"password": "Password",
"pin": "PIN",
"signIn": "Sign in",
"otherAccount": "Use another account",
"supportLink": "Support access"
},
"support": {
"title": "Support access",
"intro": "Read this code to Xenia support. They will give you a code back.",
"challenge": "Code for support",
"answer": "Support's code",
"verify": "Open support session",
"newChallenge": "New code",
"back": "Back to sign in",
"expires": "This code is valid until {{time}}."
},
"license": {
"expired": "The license has expired. This venue runs the free version until it's renewed: some features are off.",
"inactive": "The license isn't active. This venue runs the free version: some features are off.",
"locked": "The license provider locked this venue. It runs the free version: some features are off.",
"clock": "The server's clock went back in time, so the license can't be trusted. Fix the server's date and time or connect it to the internet.",
"unverified": "The license hasn't been verified yet (no connection to the license server). This venue runs the free version for now."
},
"lock": {
"title": "Locked",
"signOutInstead": "Sign out instead"
}
}
+1
View File
@@ -34,6 +34,7 @@ export function useUiLabels() {
moreInfo: t('ui.moreInfo'),
notifications: t('ui.notifications'),
backspace: t('ui.backspace'),
submit: t('ui.submit'),
pinProgress: (count, total) => t('ui.pinProgress', { count, total }),
}), [t, language]) // eslint-disable-line react-hooks/exhaustive-deps
}
+2
View File
@@ -193,6 +193,8 @@
.x-pinpad__key:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
.x-pinpad__key:disabled { opacity: 0.5; cursor: not-allowed; }
.x-pinpad__key--backspace { background: transparent; color: var(--x-ink-2); }
.x-pinpad__key--submit { background: var(--x-accent); color: var(--x-accent-fg); }
.x-pinpad__key--submit:hover:not(:disabled) { background: var(--x-accent-strong); }
@keyframes x-shake {
20% { transform: translateX(-8px); } 40% { transform: translateX(7px); }
60% { transform: translateX(-5px); } 80% { transform: translateX(3px); }
+38 -17
View File
@@ -1,32 +1,40 @@
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
import { cx } from '../internal/cx.js'
import { Spinner } from './Spinner.jsx'
import { nextPin, pinAction } from './pin.js'
import { canSubmit, nextPin, pinAction } from './pin.js'
import { useLabels } from './labels.js'
const KEYS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', null, '0', 'Backspace']
const KEYS_VARIABLE = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'Enter', '0', 'Backspace']
/**
* Numeric PIN entry: dots + a 3×4 keypad, also driven by the physical keyboard.
*
* <PinPad length={4} onComplete={async pin => { await unlock(pin) }} />
*
* onComplete(pin) runs when `length` digits are in. If it returns a promise the pad
* Fixed length (`length`, default 4): onComplete(pin) runs as soon as `length` digits are in.
* Variable length (`minLength` + `maxLength`, e.g. PINs of 4–8 digits): an OK key (and the
* Enter key) submits once at least `minLength` digits are in.
*
* If onComplete returns a promise the pad
* shows a spinner until it settles. If it throws / rejects (or returns false), the pad
* shakes, shows `error` text if given, and clears for another try. On success it clears too.
*
* error: text under the dots (e.g. "Wrong PIN"); a change of it also shakes the pad.
* captureKeyboard (default true): digits/Backspace typed anywhere go to the pad,
* except while the user is typing in a field.
* backspaceLabel / progressLabel(n, length) override the UiLabelsProvider texts.
* backspaceLabel / submitLabel / progressLabel(n, length) override the UiLabelsProvider texts.
*/
export function PinPad({
length = 4, onComplete, onChange, disabled = false, error, title,
captureKeyboard = true, backspaceLabel, progressLabel, className,
length = 4, minLength, maxLength, onComplete, onChange, disabled = false, error, title,
captureKeyboard = true, backspaceLabel, submitLabel, progressLabel, className,
}) {
const labels = useLabels()
const backspaceText = backspaceLabel ?? labels.backspace
const submitText = submitLabel ?? labels.submit
const progress = progressLabel ?? labels.pinProgress
const variable = minLength != null && maxLength != null
const max = variable ? maxLength : length
const [value, setValue] = useState('')
const [busy, setBusy] = useState(false)
const [shake, setShake] = useState(0)
@@ -61,12 +69,16 @@ export function PinPad({
const { value: current, busy: isBusy, disabled: isDisabled } = latest.current
const action = pinAction(key)
if (!action || isBusy || isDisabled) return
const next = nextPin(current, action, length)
if (action.type === 'submit') {
if (variable && canSubmit(current, minLength)) submit(current)
return
}
const next = nextPin(current, action, max)
if (next === current) return
setValue(next)
onChange?.(next)
if (next.length === length) submit(next)
}, [length, onChange, submit])
if (!variable && next.length === max) submit(next)
}, [variable, minLength, max, onChange, submit])
useEffect(() => {
if (!captureKeyboard) return
@@ -74,38 +86,47 @@ export function PinPad({
if (e.ctrlKey || e.metaKey || e.altKey) return
const t = e.target
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return
if (pinAction(e.key)) { e.preventDefault(); press(e.key) }
const action = pinAction(e.key)
if (!action || (action.type === 'submit' && !variable)) return // Enter only means "OK" in variable mode
e.preventDefault()
press(e.key)
}
document.addEventListener('keydown', onKey)
return () => document.removeEventListener('keydown', onKey)
}, [captureKeyboard, press])
}, [captureKeyboard, press, variable])
return (
<div className={cx('x-pinpad', disabled && 'x-pinpad--disabled', className)}>
{title && <div className="x-pinpad__title">{title}</div>}
{/* Re-keyed on every failed attempt and on every new error text, which replays the shake */}
<div key={`${shake}:${error || ''}`} className={cx('x-pinpad__dots', (shake > 0 || error) && 'x-pinpad__dots--shake')} aria-hidden="true">
{Array.from({ length }, (_, i) => (
{Array.from({ length: variable ? Math.max(minLength, value.length) : max }, (_, i) => (
<span key={i} className={cx('x-pinpad__dot', i < value.length && 'x-pinpad__dot--filled', error && 'x-pinpad__dot--error')} />
))}
</div>
<div className="x-visually-hidden" aria-live="polite">{progress(value.length, length)}</div>
<div className="x-visually-hidden" aria-live="polite">{progress(value.length, variable ? minLength : max)}</div>
<div className="x-pinpad__status">
{busy ? <Spinner size="sm" /> : error ? <span className="x-pinpad__error" role="alert">{error}</span> : null}
</div>
<div className="x-pinpad__keys">
{KEYS.map(k => k === null
{(variable ? KEYS_VARIABLE : KEYS).map(k => k === null
? <span key="blank" aria-hidden="true" />
: (
<button
key={k}
type="button"
className={cx('x-pinpad__key', k === 'Backspace' && 'x-pinpad__key--backspace')}
className={cx('x-pinpad__key', k === 'Backspace' && 'x-pinpad__key--backspace', k === 'Enter' && 'x-pinpad__key--submit')}
onClick={() => press(k)}
disabled={disabled || busy}
aria-label={k === 'Backspace' ? backspaceText : undefined}
disabled={disabled || busy || (k === 'Enter' && !canSubmit(value, minLength))}
aria-label={k === 'Backspace' ? backspaceText : k === 'Enter' ? submitText : undefined}
>
{k === 'Backspace'
{k === 'Enter'
? (
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M5 12.5l4.5 4.5L19 7.5" />
</svg>
)
: k === 'Backspace'
? (
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M21 5H9l-6 7 6 7h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1z" /><path d="M17 9l-6 6M11 9l6 6" />
+1
View File
@@ -12,6 +12,7 @@ export const DEFAULT_LABELS = {
moreInfo: 'More info',
notifications: 'Notifications',
backspace: 'Delete',
submit: 'OK',
pinProgress: (n, total) => `${n} of ${total} digits entered`,
}
+6
View File
@@ -4,9 +4,15 @@
export function pinAction(key) {
if (/^[0-9]$/.test(key)) return { type: 'digit', digit: key }
if (key === 'Backspace' || key === 'Delete') return { type: 'backspace' }
if (key === 'Enter') return { type: 'submit' }
return null
}
/** Variable-length mode: may this value be submitted? */
export function canSubmit(value, minLength) {
return value.length >= minLength
}
/**
* Next PIN value. Digits are ignored once `length` is reached; backspace on an
* empty PIN is a no-op; 'clear' empties it.
+11 -2
View File
@@ -1,12 +1,13 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { nextPin, pinAction } from '../src/components/pin.js'
import { canSubmit, nextPin, pinAction } from '../src/components/pin.js'
test('keys map to actions', () => {
assert.deepEqual(pinAction('7'), { type: 'digit', digit: '7' })
assert.deepEqual(pinAction('Enter'), { type: 'submit' })
assert.deepEqual(pinAction('Backspace'), { type: 'backspace' })
assert.deepEqual(pinAction('Delete'), { type: 'backspace' })
for (const k of ['a', 'Enter', 'Escape', ' ', '12', '']) assert.equal(pinAction(k), null, k)
for (const k of ['a', 'Escape', ' ', '12', '']) assert.equal(pinAction(k), null, k)
})
test('digits stop at the length', () => {
@@ -21,3 +22,11 @@ test('backspace and clear', () => {
assert.equal(nextPin('123', { type: 'clear' }, 4), '')
assert.equal(nextPin('12', null, 4), '12')
})
test('variable length: submit only from minLength, digits stop at maxLength', () => {
assert.equal(canSubmit('123', 4), false)
assert.equal(canSubmit('1234', 4), true)
let v = ''
for (const k of '1234567890') v = nextPin(v, pinAction(k), 8)
assert.equal(v, '12345678')
})