isLoggedIn()) { if ($auth->isAdmin()) { header('Location: /admin/index.php'); } else { header('Location: /ayudante.php'); } exit; } $error = ''; $loginInput = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!CSRF::isValidRequest()) { $error = 'Error de validación del formulario'; } else { $loginInput = trim($_POST['login'] ?? ''); $password = $_POST['password'] ?? ''; if (empty($loginInput) || empty($password)) { $error = 'Por favor ingresa usuario/email y contraseña'; } else { if ($auth->login($loginInput, $password)) { if ($auth->isAdmin()) { header('Location: /admin/index.php'); } else { header('Location: /ayudante.php'); } exit; } else { $error = 'Usuario/email o contraseña incorrectos'; } } } } ?>