<?php 
if(file_exists('../../'.$_REQUEST['tenant'].'/config.php')){require_once('../../'.$_REQUEST['tenant'].'/config.php');}
if(file_exists('/config.php')){require_once('/config.php');}
// Verify the token and email
$token = $_GET['token'] ?? '';
$email = $_GET['email'] ?? '';
$type = $_GET['type'] ?? '';

$stmt = $pdo->prepare("SELECT * FROM password_resets WHERE email = ? AND token = ? AND expires_at > NOW()");
$stmt->execute([$email, $token]);
$resetRequest = $stmt->fetch();

if (!$resetRequest) {
    echo 'Invalid or expired token';
    exit();
}

?>

<!-- Reset Password Form -->
<form action="submit_new_password.php" method="POST">
    <input type="hidden" name="token" value="<?php echo htmlspecialchars($token); ?>">
    <input type="hidden" name="email" value="<?php echo htmlspecialchars($email); ?>">
    <input type="hidden" name="type" value="<?php echo htmlspecialchars($type); ?>">
    <input type="hidden" name="tenant" value="<?php echo $_REQUEST['tenant']; ?>">
    <div>
        <input type="password" name="new_password" placeholder="Enter new password" required>
    </div>
    <div>
        <input type="password" name="confirm_password" placeholder="Confirm new password" required>
    </div>
    <button type="submit">Reset Password</button>
</form>