From 88fd0e4151d202805ddc9e83c87b981e30e0c302 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 28 Jul 2026 08:16:37 -0500 Subject: [PATCH] fix(turnero): login detecta dispositivo por token antes de buscar por IP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La detección de tablet fija solo buscaba por IP; tablets con token configurado no hacían match y caían al redirect de rol (recepcion). Ahora busca primero por cookie turnero_token y como fallback por IP. Co-Authored-By: Claude Sonnet 4.6 --- login.php | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/login.php b/login.php index e34c5da..d735a7b 100644 --- a/login.php +++ b/login.php @@ -41,16 +41,31 @@ if ($_POST && !$loginBlocked) { $_SESSION['login_ip'] = $clientIp; $_SESSION['login_time'] = time(); - // Tablet fija: redirigir al lugar asignado por IP y bloquear el resto + // Tablet fija: redirigir al lugar asignado por token o IP try { - $_dispStmt = Database::getInstance()->getConnection()->prepare( - "SELECT td.lugar_id, td.nombre, tl.tipo - FROM turnero_dispositivos td - JOIN turnero_lugares tl ON tl.id = td.lugar_id - WHERE td.ip = ? AND td.activo = 1 LIMIT 1" - ); - $_dispStmt->execute([$clientIp]); - $_disp = $_dispStmt->fetch(PDO::FETCH_ASSOC); + $_pdo2 = Database::getInstance()->getConnection(); + $_disp = null; + $_devToken = trim($_COOKIE['turnero_token'] ?? ''); + if ($_devToken) { + $_s = $_pdo2->prepare( + "SELECT td.lugar_id, td.nombre, tl.tipo + FROM turnero_dispositivos td + JOIN turnero_lugares tl ON tl.id = td.lugar_id + WHERE td.token = ? AND td.activo = 1 LIMIT 1" + ); + $_s->execute([$_devToken]); + $_disp = $_s->fetch(PDO::FETCH_ASSOC) ?: null; + } + if (!$_disp) { + $_s = $_pdo2->prepare( + "SELECT td.lugar_id, td.nombre, tl.tipo + FROM turnero_dispositivos td + JOIN turnero_lugares tl ON tl.id = td.lugar_id + WHERE td.ip = ? AND td.activo = 1 LIMIT 1" + ); + $_s->execute([$clientIp]); + $_disp = $_s->fetch(PDO::FETCH_ASSOC) ?: null; + } if ($_disp) { $_SESSION['turnero_dispositivo'] = $_disp; $url = $_disp['tipo'] === 'recepcion'