/home/awneajlw/public_html/codestechvista.com/reset_password.php
<?php
include_once "config/database.php";
session_start();

// Token handling: GET or POST
$token = $_GET['token'] ?? $_POST['token'] ?? null;
if (!$token) {
    die("Invalid request.");
}

$db = new Database();
$conn = $db->getConnection();

// Fetch user by token
$query = $conn->prepare("SELECT * FROM users WHERE reset_token = :token");
$query->execute([':token' => $token]);
$user = $query->fetch(PDO::FETCH_ASSOC);

if (!$user) {
    die("Invalid or expired token.");
}

// Check token expiry
if ($user['reset_expiry'] <= date("Y-m-d H:i:s")) {
    die("Token expired at " . $user['reset_expiry']);
}

$reset_success = false;

// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $new_password = password_hash($_POST['password'], PASSWORD_BCRYPT);

    $update = $conn->prepare("UPDATE users SET password = :password, reset_token = NULL, reset_expiry = NULL WHERE id = :id");
    $update->execute([':password' => $new_password, ':id' => $user['id']]);

    $reset_success = true;
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Reset Password</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #20B15A, #0E4B26);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .reset-container {
            background: #fff;
            padding: 50px 50px;
            border-radius: 12px;
            box-shadow: 0 10px 25px rgba(0,0,0,0.15);
            width: 100%;
            max-width: 500px;
            text-align: center;
            position: relative;
        }

        .reset-container h2 {
            margin-bottom: 20px;
            color: #333;
            font-size: 24px;
        }

        .reset-container input[type="password"] {
            width: 100%;
            padding: 15px 05px;
            margin: 12px 12px;
            border-radius: 6px;
            border: 1px solid #ccc;
            font-size: 16px;
        }

        .reset-container button {
            background-color: #4CAF50;
            color: white;
            padding: 14px 0;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            width: 50%;
            margin-top: 10px;
            transition: all 0.3s ease;
        }

        .reset-container button:hover {
            background-color: #45a049;
        }

        .notification {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #fff;
            padding: 30px 40px;
            border-radius: 12px;
            box-shadow: 0 8px 20px rgba(0,0,0,0.2);
            text-align: center;
            z-index: 100;
            animation: fadeIn 0.5s forwards;
        }

        .notification.show {
            display: block;
        }

        .notification h3 {
            margin-bottom: 15px;
            color: #4CAF50;
        }

        .notification a {
            display: inline-block;
            background: #4CAF50;
            color: #fff;
            padding: 12px 20px;
            border-radius: 6px;
            text-decoration: none;
            font-weight: bold;
            transition: 0.3s ease;
        }

        .notification a:hover {
            background: #45a049;
        }

        @keyframes fadeIn {
            from {opacity: 0; transform: translate(-50%, -55%);}
            to {opacity: 1; transform: translate(-50%, -50%);}
        }

    </style>
</head>
<body>

<div class="reset-container">
    <h2>Set a New Password</h2>
    <form method="POST">
        <input type="password" name="password" placeholder="Enter new password" required>
        <input type="hidden" name="token" value="<?php echo htmlspecialchars($token); ?>">
        <button type="submit">Reset Password</button>
    </form>
</div>

<?php if ($reset_success): ?>
<div class="notification show">
    <h3>Password Reset Successfully!</h3>
    <p>Your password has been updated. You can now login.</p>
    <a href="signin.php">Login Now</a>
</div>
<script>
    // Optional: auto-hide notification after 5 sec
    setTimeout(() => {
        document.querySelector('.notification').style.display = 'none';
    }, 7000);
</script>
<?php endif; ?>

</body>
</html>