<?php
session_start();
require_once __DIR__ . '/../app/Core/Database.php';
require_once __DIR__ . '/../app/Controllers/AuthController.php';

$db = (new Database())->conn;
$auth = new AuthController($db);

$error = '';

//echo $_SESSION['token_login'];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $token = $_POST['token'];
    if ($auth->verificarToken($token)) {
        header('Location: dashboard.php');
        exit;
    } else {
        $error = 'Token inválido o expirado.';
    }
}
?>

<!DOCTYPE html>
<html lang="es">

<head>

    <!--meta name="viewport" content="width=device-width, initial-scale=1.0"-->
    <meta name="viewport" content="width=device-width, user-scalable=no" />
    <meta charset="UTF-8">
    <title>Verificación de Token</title>
    <link rel="stylesheet" href="assets/css/plugins/bootstrap.min.css">
</head>

<body class="container py-5">
    <h2>Ingresa el código que se te envió</h2>

    <?php if (!empty($error)) : ?>
        <div class="alert alert-danger"><?php echo $error; ?></div>
    <?php endif; ?>

    <form method="POST">
        <div class="mb-3">
            <label for="token" class="form-label">Código de verificación</label>
            <input type="text" class="form-control" name="token" id="token" required>
        </div>
        <button type="submit" class="btn btn-success">Verificar</button>
    </form>
</body>

</html>