From b2c161b88cdd47bf23558b78ef1ad4cdfe81659c Mon Sep 17 00:00:00 2001 From: Collina Systems Date: Sat, 4 Jul 2026 22:53:17 -0600 Subject: [PATCH] =?UTF-8?q?feat(entrada):=20GET=20/e/nfc=20=E2=80=94=20ven?= =?UTF-8?q?tana=20horaria=20=E2=86=92=20token=20de=205=20min=20=E2=86=92?= =?UTF-8?q?=20302?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dentro de la ventana emite token y redirige a /checada.html?t=; fuera, redirige a /checada.html?cerrado=1 sin emitir token (§3.2). Público: el token sin sesión de becario no sirve para checar. --- backend/src/index.js | 2 ++ backend/src/routes/entrada.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 backend/src/routes/entrada.js diff --git a/backend/src/index.js b/backend/src/index.js index 2c70f83..45ca4b7 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -12,6 +12,7 @@ import jornadasRoutes from './routes/jornadas.js'; import ajustesRoutes from './routes/ajustes.js'; import becarioAuthRoutes from './routes/becario-auth.js'; import becarioPortalRoutes from './routes/becario-portal.js'; +import entradaRoutes from './routes/entrada.js'; const fastify = Fastify({ // node vive detrás del nginx del propio container (y de Traefik en prod): @@ -89,6 +90,7 @@ await fastify.register(jornadasRoutes, { prefix: '/api' }); await fastify.register(ajustesRoutes, { prefix: '/api' }); await fastify.register(becarioAuthRoutes, { prefix: '/api' }); await fastify.register(becarioPortalRoutes, { prefix: '/api' }); +await fastify.register(entradaRoutes, { prefix: '/e' }); try { const address = await fastify.listen({ port: config.apiPort, host: config.apiHost }); diff --git a/backend/src/routes/entrada.js b/backend/src/routes/entrada.js new file mode 100644 index 0000000..6fac3ee --- /dev/null +++ b/backend/src/routes/entrada.js @@ -0,0 +1,24 @@ +import { getVentana, dentroDeVentana } from '../services/config.js'; +import { emitirToken } from '../services/tokens.js'; + +// Redirect del NFC fijo (§3). El chip guarda la URL fija /e/nfc; el servidor +// produce la unicidad y temporalidad. Público: cualquiera que escanee obtiene +// un token, pero sin sesión de becario no puede checar (POST /api/checadas). +// Registrado con prefix '/e' (nginx proxya /e/ a node). + +export default async function entradaRoutes(fastify) { + fastify.get('/nfc', async (req, reply) => { + const ahora = new Date(); + const ventana = await getVentana(fastify.db); + + // Solo dentro de la ventana horaria activa se emite token (§3.2). + if (!dentroDeVentana(ahora, ventana)) { + req.log.info({ ventana }, 'Escaneo NFC fuera de ventana → checado cerrado'); + return reply.redirect('/checada.html?cerrado=1', 302); + } + + const { token } = await emitirToken(fastify.db, { origen: 'nfc' }); + // base64url es URL-safe: no requiere encoding. + return reply.redirect(`/checada.html?t=${token}`, 302); + }); +}