<?php
header('Content-Type: text/plain; charset=utf-8');
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once __DIR__ . '/db_config.php';

$conn = $conn;  // Already set by db_config.php
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset('utf8mb4');

echo "===== DEBUG: Reset Token Check =====\n\n";

// Check all users with active reset tokens
$res = $conn->query("SELECT `sno`, `name`, `email`, `reset_token`, `reset_expiry` FROM `login-t` WHERE `reset_token` IS NOT NULL");
echo "Users with active reset tokens:\n";
echo str_repeat("-", 120) . "\n";
if ($res && $res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        echo "ID: " . $row['sno'] . "\n";
        echo "Name: " . $row['name'] . "\n";
        echo "Email: " . $row['email'] . "\n";
        echo "Token: " . substr($row['reset_token'], 0, 20) . "...\n";
        echo "Expiry: " . $row['reset_expiry'] . "\n";
        echo "Expired? " . (strtotime($row['reset_expiry']) < time() ? "YES" : "NO") . "\n";
        echo "\n";
    }
} else {
    echo "No users with active reset tokens.\n";
}

echo "\n===== Table Structure =====\n";
$res = $conn->query("DESCRIBE `login-t`");
while ($row = $res->fetch_assoc()) {
    echo "  " . str_pad($row['Field'], 20) . " | " . $row['Type'] . "\n";
}

$conn->close();
?>
