- kiosco.html: la asistente entra con la cuenta de supervisora y muestra un QR que rota cada rotacion_seg (POST /api/kiosco/qr). El QR codifica la URL a /checada.html?t=<token>; el becario lo escanea con su teléfono y su sesión pone la identidad. Estado "checado cerrado" fuera de ventana. QR vía qrcodejs (cdnjs), componentes cream de theme.js. - Dockerfile: hornea kiosco.html en la imagen (nginx ya lo sirve por try_files). - panel.html: en Configuración, perilla "Rotación del QR (segundos)" (10–300) y botón "Abrir pantalla de kiosco". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
170 lines
8.4 KiB
HTML
170 lines
8.4 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="es">
|
||
<head>
|
||
<meta charset="UTF-8"/>
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||
<title>Taboada — Kiosco</title>
|
||
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||
<link href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700&family=Figtree:wght@400;500;600;700&display=swap" rel="stylesheet"/>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.23.2/babel.min.js"></script>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
|
||
<script src="theme.js"></script>
|
||
<style>
|
||
* { box-sizing: border-box; }
|
||
html, body { margin: 0; padding: 0; }
|
||
body { background: #F3EBDD; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
|
||
input::placeholder { color: #B4A99A; }
|
||
@keyframes tb-spin { to { transform: rotate(360deg); } }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div id="root"></div>
|
||
<script type="text/babel" data-presets="react">
|
||
const { useState, useEffect, useRef, useCallback } = React;
|
||
|
||
// Pantalla de kiosco (vector de presencia por QR). La abre la asistente en su
|
||
// teléfono con la cuenta de supervisora (misma cookie/guardia que el panel).
|
||
// Muestra un QR rotativo; el becario lo escanea con SU teléfono y aterriza en
|
||
// /checada.html?t=<token>, donde su propia sesión pone la identidad.
|
||
const { apiFetch } = Theme;
|
||
const UI = Theme.makeUI("checada"); // piel cream móvil
|
||
const { Logo, Card, Btn, Input, Aviso, Estado, palette, fonts, icons } = UI;
|
||
|
||
const Shell = ({ children }) => (
|
||
<div style={{ minHeight: "100vh", background: palette.bgGradient, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", padding: "28px 20px", fontFamily: fonts.body }}>
|
||
<div style={{ width: "100%", maxWidth: "420px" }}>
|
||
<div style={{ display: "flex", justifyContent: "center", marginBottom: "22px" }}><Logo /></div>
|
||
{children}
|
||
</div>
|
||
</div>
|
||
);
|
||
|
||
const Cargando = ({ texto = "Cargando…" }) => (
|
||
<Card style={{ textAlign: "center" }}>
|
||
<div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: "12px" }}>
|
||
<span style={{ display: "inline-flex" }}>{icons.spinner({ size: 24, color: palette.primary, track: palette.line })}</span>
|
||
<span style={{ fontFamily: fonts.body, fontSize: "14px", color: palette.inkSoft }}>{texto}</span>
|
||
</div>
|
||
</Card>
|
||
);
|
||
|
||
// ═══════════════ Login de la asistente (cuenta de supervisora) ═══════════════
|
||
function Login({ onEntra }) {
|
||
const [f, setF] = useState({ usuario: "", password: "" });
|
||
const [error, setError] = useState(null);
|
||
const [busy, setBusy] = useState(false);
|
||
const submit = async (e) => {
|
||
e.preventDefault(); setBusy(true); setError(null);
|
||
try {
|
||
await apiFetch("/auth/login", { method: "POST", body: JSON.stringify(f) });
|
||
onEntra(await apiFetch("/auth/session"));
|
||
} catch (err) {
|
||
setError(err.status === 429 ? { text: "Demasiados intentos, espera un minuto.", ic: "clock" }
|
||
: { text: "Usuario o contraseña incorrectos.", ic: "alertCircle" });
|
||
} finally { setBusy(false); }
|
||
};
|
||
return (
|
||
<Card>
|
||
<h2 style={{ margin: "0 0 4px", fontFamily: fonts.title, fontWeight: 600, letterSpacing: "-.01em", color: palette.ink, fontSize: "22px", textAlign: "center" }}>Abrir kiosco</h2>
|
||
<p style={{ margin: "0 0 18px", fontFamily: fonts.body, color: palette.inkSoft, fontSize: "13px", textAlign: "center" }}>Inicia sesión para mostrar el código de checada.</p>
|
||
{error && <Aviso variant="error" icon={error.ic}>{error.text}</Aviso>}
|
||
<form onSubmit={submit}>
|
||
<div style={{ marginBottom: "12px" }}>
|
||
<Input placeholder="Usuario" value={f.usuario} onChange={(e) => setF({ ...f, usuario: e.target.value })} autoComplete="username" required />
|
||
</div>
|
||
<div style={{ marginBottom: "16px" }}>
|
||
<Input type="password" placeholder="Contraseña" value={f.password} onChange={(e) => setF({ ...f, password: e.target.value })} autoComplete="current-password" required />
|
||
</div>
|
||
<Btn type="submit" loading={busy} disabled={busy || !f.usuario || !f.password}>{busy ? "Entrando…" : "Entrar"}</Btn>
|
||
</form>
|
||
</Card>
|
||
);
|
||
}
|
||
|
||
// ═══════════════ Kiosco: QR rotativo ═══════════════
|
||
function Kiosco({ onSalir }) {
|
||
const [estado, setEstado] = useState(undefined); // undefined=cargando · {cerrado,token,rotacion_seg,...}
|
||
const [error, setError] = useState(null);
|
||
const qrHost = useRef(null); // div donde qrcodejs pinta
|
||
const qrObj = useRef(null); // instancia QRCode
|
||
const timer = useRef(null);
|
||
|
||
// Pide un token nuevo al servidor. 401 → sesión caída, vuelve al login.
|
||
const emitir = useCallback(async () => {
|
||
try {
|
||
const r = await apiFetch("/kiosco/qr", { method: "POST" });
|
||
setError(null); setEstado(r);
|
||
} catch (err) {
|
||
if (err.status === 401) { onSalir(); return; }
|
||
setError(err.status === 429 ? "Demasiadas solicitudes; espera un momento." : "No se pudo generar el código. Reintentando…");
|
||
}
|
||
}, [onSalir]);
|
||
|
||
useEffect(() => { emitir(); }, [emitir]);
|
||
|
||
// Reprograma la siguiente emisión según la rotación que devuelve el servidor.
|
||
// El token viejo sigue válido hasta su expiración (validez = rotacion×2), así
|
||
// que quien escanee justo en el cambio no se queda con un QR muerto.
|
||
useEffect(() => {
|
||
if (!estado) return;
|
||
const secs = estado.rotacion_seg || 45;
|
||
timer.current = setTimeout(emitir, secs * 1000);
|
||
return () => clearTimeout(timer.current);
|
||
}, [estado, emitir]);
|
||
|
||
// Repinta el QR cuando cambia el token (URL absoluta a /checada.html?t=…).
|
||
useEffect(() => {
|
||
if (!estado || estado.cerrado || !estado.token || !qrHost.current) return;
|
||
const url = `${window.location.origin}/checada.html?t=${estado.token}`;
|
||
if (!qrObj.current) {
|
||
qrObj.current = new QRCode(qrHost.current, { text: url, width: 264, height: 264, correctLevel: QRCode.CorrectLevel.M });
|
||
} else {
|
||
qrObj.current.clear();
|
||
qrObj.current.makeCode(url);
|
||
}
|
||
}, [estado]);
|
||
|
||
if (estado === undefined) return <Shell><Cargando texto="Generando código…" /></Shell>;
|
||
|
||
if (estado.cerrado) return (
|
||
<Shell>
|
||
<Estado icon="clock" tone="amber" title="Checado cerrado"
|
||
sub={`Fuera del horario de operación (${estado.ventana?.inicio}–${estado.ventana?.fin}). El código volverá al abrir la ventana.`}
|
||
action={<Btn variant="ghost" onClick={onSalir}>Cerrar kiosco</Btn>} />
|
||
</Shell>
|
||
);
|
||
|
||
return (
|
||
<Shell>
|
||
<Card style={{ textAlign: "center" }}>
|
||
<h2 style={{ margin: "0 0 4px", fontFamily: fonts.title, fontWeight: 600, letterSpacing: "-.01em", color: palette.ink, fontSize: "22px" }}>Escanea para checar</h2>
|
||
<p style={{ margin: "0 0 18px", fontFamily: fonts.body, color: palette.inkSoft, fontSize: "13px" }}>Acerca tu teléfono y escanea este código con la cámara.</p>
|
||
<div style={{ display: "flex", justifyContent: "center", marginBottom: "16px" }}>
|
||
<div ref={qrHost} style={{ display: "inline-block", padding: "16px", background: "#fff", borderRadius: "18px", border: `1px solid ${palette.cardBorder}`, lineHeight: 0 }} />
|
||
</div>
|
||
{error && <Aviso variant="error" icon="alertCircle">{error}</Aviso>}
|
||
<p style={{ margin: "0 0 16px", fontFamily: fonts.body, color: palette.inkSoft, fontSize: "12px" }}>
|
||
El código cambia cada {estado.rotacion_seg}s. Cada uno sirve una sola vez.
|
||
</p>
|
||
<Btn variant="ghost" onClick={onSalir}>Cerrar kiosco</Btn>
|
||
</Card>
|
||
</Shell>
|
||
);
|
||
}
|
||
|
||
function App() {
|
||
const [session, setSession] = useState(undefined);
|
||
useEffect(() => { apiFetch("/auth/session").then(setSession).catch(() => setSession(null)); }, []);
|
||
const salir = async () => { try { await apiFetch("/auth/logout", { method: "POST" }); } catch {} setSession(null); };
|
||
if (session === undefined) return <Shell><Cargando texto="Verificando sesión…" /></Shell>;
|
||
if (!session) return <Login onEntra={setSession} />;
|
||
return <Kiosco onSalir={salir} />;
|
||
}
|
||
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
|
||
</script>
|
||
</body>
|
||
</html>
|