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
+69 -15
View File
@@ -11,6 +11,7 @@ import path from 'node:path'
import { chromium } from 'playwright'
import { BROWSER_CHANNEL, CS, OUT, reporter, sleep } from './lib/env.mjs'
import { killTree, startBackend, waitHttp } from './lib/proc.mjs'
import { SUPPORT_MASTER, codeFor, siteSecret } from './lib/support.mjs'
const PORT = 5186
const APP = `http://localhost:${PORT}`
@@ -38,14 +39,13 @@ const loginApi = (username, secret) => api('POST', '/api/auth/login', { body: {
async function uiLogin(page, password) {
await page.goto(`${APP}/login`)
await page.waitForFunction(() => document.body.innerText.includes('Sign In'), null, { timeout: 60_000 })
const other = page.getByText('Sign in as different account')
if (await other.count()) { await other.click(); await sleep(300) }
const user = page.locator('input:not([type=password])').first()
if (await user.count()) await user.fill('manager')
await page.locator('input[type=password]').fill(password)
await page.getByRole('button', { name: 'Sign In' }).click()
await page.getByTestId('login-form').waitFor({ timeout: 60_000 })
if (!(await page.getByTestId('login-account').count())) await page.getByLabel('Username').fill('manager')
await page.getByLabel('Password').fill(password)
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
}
const typePin = async (page, pin) => { for (const d of pin) { await page.keyboard.type(d); await sleep(80) } await page.keyboard.press('Enter') }
const setSetting = (token, key, value) => api('PUT', `/api/settings/${key}`, { token, body: { value } })
try {
await waitHttp(`${APP}/`)
@@ -61,12 +61,13 @@ try {
await page.evaluate(() => { window.__noReload = true })
await sleep(1500)
r.check('bootstrap loaded before login (anonymous)', bootstraps[0] === 'anonymous', bootstraps.join(','))
await page.screenshot({ path: path.join(OUT, 'manager-login-wrong-password.png') })
r.check('wrong password: error shown, page not reloaded',
await page.getByText('Wrong username or password').count() > 0 && await page.evaluate(() => window.__noReload === true))
// ── Right password: dashboard, bootstrap again with the session ────────────
await page.locator('input[type=password]').fill('password')
await page.getByRole('button', { name: 'Sign In' }).click()
await page.getByLabel('Password').fill('password')
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 15_000 }).catch(() => {})
await sleep(1500)
r.check('login → /dashboard', new URL(page.url()).pathname === '/dashboard', page.url())
@@ -112,13 +113,17 @@ try {
await sleep(1500)
await page.locator('header button').filter({ has: page.locator('svg.lucide-lock') }).first().click()
await sleep(600)
for (const d of '0000') { await page.keyboard.type(d); await sleep(120) }
const tokenBeforeLock = await page.evaluate(() => localStorage.getItem('manager_token'))
await typePin(page, '0000')
await sleep(1500)
r.check('lock: wrong PIN → "Wrong PIN", still signed in',
await page.getByText('Wrong PIN').count() > 0 && !!(await page.evaluate(() => localStorage.getItem('manager_token'))) && new URL(page.url()).pathname === '/dashboard')
for (const d of '1234') { await page.keyboard.type(d); await sleep(120) }
await page.screenshot({ path: path.join(OUT, 'manager-lock-wrong-pin.png') })
r.check('lock: wrong PIN → "Wrong PIN. 4 tries left…", still signed in',
await page.getByTestId('lock-screen').getByText('Wrong PIN. 4 tries left').count() === 1 && !!(await page.evaluate(() => localStorage.getItem('manager_token'))) && new URL(page.url()).pathname === '/dashboard')
await typePin(page, '1234')
await sleep(2000)
r.check('lock: right PIN unlocks', await page.getByText('Locked').count() === 0 && new URL(page.url()).pathname === '/dashboard')
r.check('lock: right PIN unlocks the SAME session (token unchanged)',
await page.getByTestId('lock-screen').count() === 0 && new URL(page.url()).pathname === '/dashboard'
&& await page.evaluate(() => localStorage.getItem('manager_token')) === tokenBeforeLock)
// ── A module turned off: /kds shows the "turned off" screen ────────────────
const mgr = await page.evaluate(() => localStorage.getItem('manager_token'))
@@ -131,10 +136,59 @@ try {
await sleep(2000)
r.check('kds on again → the KDS renders', await page.locator('.x-empty__title').count() === 0)
// ── 2.6b: five wrong PINs on the lock screen end the session ───────────────
await page.goto(`${APP}/dashboard`)
await sleep(1500)
await page.locator('header button').filter({ has: page.locator('svg.lucide-lock') }).first().click()
await sleep(500)
for (let i = 0; i < 5; i++) { await typePin(page, '0000'); await sleep(900) }
await page.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).catch(() => {})
const endedToken = mgr
r.check('lock: 5 wrong PINs → signed out', new URL(page.url()).pathname === '/login' && !(await page.evaluate(() => localStorage.getItem('manager_token'))), page.url())
r.check('…and that session is really over on the server', await api('GET', '/api/auth/me', { token: endedToken }).then(() => false, e => e.message.includes('401')))
// ── 2.6b: PIN login mode ───────────────────────────────────────────────────
const owner = await loginApi('manager', { password: 'password', client: 'manager' })
await setSetting(owner, 'auth.manager_login_mode', 'pin')
await page.goto(`${APP}/login`)
await page.getByTestId('login-form').waitFor()
if (!(await page.getByTestId('login-account').count())) await page.getByLabel('Username').fill('manager')
r.check('pin mode: the login shows a PIN pad, no password field', await page.locator('.x-pinpad').count() === 1 && await page.getByLabel('Password').count() === 0)
await page.locator('.x-pinpad').getByRole('button', { name: '1', exact: true }).click()
for (const d of '234') await page.locator('.x-pinpad').getByRole('button', { name: d, exact: true }).click()
await page.locator('.x-pinpad').getByRole('button', { name: 'OK' }).click()
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 10_000 }).catch(() => {})
r.check('pin mode: PIN → /dashboard', new URL(page.url()).pathname === '/dashboard', page.url())
await setSetting(owner, 'auth.manager_login_mode', 'password')
const mgr2 = await page.evaluate(() => localStorage.getItem('manager_token'))
await page.evaluate(() => { localStorage.removeItem('manager_token') })
await page.goto('about:blank') // leave first: the open page would redirect itself on the 401
await api('POST', '/api/auth/logout', { token: mgr2 })
// ── 2.6b: support access from the login screen ─────────────────────────────
await page.goto(`${APP}/login`)
await page.getByTestId('login-title').waitFor()
await page.getByRole('button', { name: 'Support access' }).click()
const challenge = (await page.getByTestId('support-challenge').textContent({ timeout: 10_000 })).trim()
await page.screenshot({ path: path.join(OUT, 'manager-support-access.png') })
r.check('support: a challenge code is shown', /^[A-Z0-9]{4}-[A-Z0-9]{4}$/.test(challenge), challenge)
await page.getByLabel("Support's code").fill('WRONGCODE1')
await page.getByRole('button', { name: 'Open support session' }).click()
await sleep(1000)
r.check('support: a wrong code is refused with a message', await page.getByText('That support code is wrong').count() === 1)
await page.getByLabel("Support's code").fill(codeFor(siteSecret(SUPPORT_MASTER, 'test-site-1'), 'test-site-1', challenge))
await page.getByRole('button', { name: 'Open support session' }).click()
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 10_000 }).catch(() => {})
r.check('support: the right code opens a session', new URL(page.url()).pathname === '/dashboard', page.url())
await page.evaluate(() => { localStorage.removeItem('manager_token') })
await uiLogin(page, 'password')
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 10_000 }).catch(() => {})
const mgr3 = await page.evaluate(() => localStorage.getItem('manager_token'))
// ── Session ended elsewhere: the next request logs out ─────────────────────
await page.goto(`${APP}/dashboard`)
await sleep(1500)
await api('POST', '/api/auth/logout', { token: mgr })
await api('POST', '/api/auth/logout', { token: mgr3 })
await sidebar.getByText('Reports').first().click()
await sidebar.getByText('Today').first().click()
await page.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).catch(() => {})