/home/awneajlw/public_html/codestechvista.com/forgot_password.php
<?php
session_start();
include_once "config/database.php";
require_once __DIR__ . "/includes/email.php";

$msg = "";

// Database connection
$database = new Database();
$conn = $database->getConnection();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $email = trim($_POST['email']);

    // Check email exists
    $stmt = $conn->prepare("SELECT * FROM users WHERE email = :email LIMIT 1");
    $stmt->bindParam(":email", $email);
    $stmt->execute();

    if ($stmt->rowCount() > 0) {
        $token = bin2hex(random_bytes(50));
        $expiry = date("Y-m-d H:i:s", strtotime("+1 hour"));

        // Save token
        $update = $conn->prepare("UPDATE users SET reset_token=:token, reset_expiry=:expiry WHERE email=:email");
        $update->bindParam(":token", $token);
        $update->bindParam(":expiry", $expiry);
        $update->bindParam(":email", $email);
        $update->execute();

        // Reset link
        $reset_link = "https://codestechvista.com/reset_password.php?token=" . $token;

        // Send Email
        if (sendResetEmail($email, $reset_link)) {
            $msg = "<div class='alert alert-success'>Password reset link sent to your email.</div>";
        } else {
            $msg = "<div class='alert alert-danger'>Failed to send email. Please try again.</div>";
        }
    } else {
        $msg = "<div class='alert alert-danger'>Email not found in system.</div>";
    }
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FORGOT PASSWORD - OPTI SLIP</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            font-family: 'Inter', sans-serif;
            min-height: 100vh;
            background: #f8fafc;
            margin: 0;
        }

        .main-container {
            display: flex;
            min-height: 100vh;
            width: 100%;
            background: #fff;
        }

        .left-section {
            flex: 1;
            background: #169D53;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 60px 40px;
            clip-path: polygon(0 0, 100% 0, 65% 100%, 0% 100%);
            color: white;
        }

        .logo-container {
            text-align: center;
            margin-bottom: 30px;
        }

        .logo-image {
            width: 180px;
            height: auto;
            border-radius: 50%;
            object-fit: contain;
            display: block;
            margin: 0 auto;
        }

        .description-text {
            color: white;
            font-size: 16px;
            text-align: center;
            max-width: 300px;
            opacity: 0.95;
        }

        .right-section {
            flex: 1;
            background: white;
            display: flex;
            flex-direction: column;
            justify-content: center;
            padding: 60px 50px;
        }

        .welcome-text {
            font-size: 40px;
            font-weight: 700;
            color: #1f2937;
            margin-bottom: 30px;
        }

        .form-container {
            max-width: 400px;
            width: 100%;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            display: block;
            font-size: 14px;
            font-weight: 600;
            color: #374151;
            margin-bottom: 8px;
        }

        .form-input {
            width: 100%;
            padding: 16px 18px;
            border: 2px solid #e5e7eb;
            border-radius: 12px;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        .form-input:focus {
            border-color: #169D53;
            box-shadow: 0 0 0 3px rgba(22, 157, 83, 0.1);
            outline: none;
        }

        .submit-btn {
            width: 100%;
            padding: 16px;
            background: #169D53;
            color: white;
            border: none;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 600;
            text-transform: uppercase;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 15px;
            box-shadow: 0 4px 12px rgba(22, 157, 83, 0.3);
        }

        .submit-btn:hover {
            background: #138043;
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(22, 157, 83, 0.4);
        }

        .back-link {
            margin-top: 20px;
            text-align: center;
            font-size: 14px;
        }

        .back-link a {
            color: #169D53;
            text-decoration: none;
            font-weight: 600;
        }

        .back-link a:hover {
            text-decoration: underline;
        }

        @media (max-width: 768px) {
            .main-container {
                flex-direction: column;
            }
            .left-section {
                clip-path: none;
                padding: 40px 20px;
            }
            .right-section {
                padding: 40px 20px;
            }
            .welcome-text {
                font-size: 30px;
            }
        }
    </style>
</head>
<body>
    <div class="main-container">
        <!-- Left Section -->
        <div class="left-section">
            <div class="logo-container">
                <img src="assets/images/OptiSlip.png" alt="Opti Slip Logo" class="logo-image">
            </div>
            <div class="description-text">
                Enter your registered email address and we'll send you a link to reset your password.
            </div>
        </div>

        <!-- Right Section -->
        <div class="right-section">
            <div class="welcome-text">Forgot Password</div>
            <div class="form-container">
                <form method="POST" action="">
                    <div class="form-group">
                        <label class="form-label">Email Address</label>
                        <input type="email" name="email" class="form-input" placeholder="you@example.com" required>
                    </div>
                    <button type="submit" class="submit-btn">Send Reset Link</button>
                </form>
                <div class="back-link">
                    <a href="signin.php"><i class="fas fa-arrow-left me-1"></i> Back to Sign In</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>