Path : /home/vishqocm/pcib.in/a/login/
File Upload :
Current File : /home/vishqocm/pcib.in/a/login/reset-password.php

<?php
require_once 'includes/auth.php';

$error = '';
$success = '';

if (!isset($_GET['token'])) {
    header('Location: login.php');
    exit;
}

$token = $_GET['token'];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $password = $_POST['password'] ?? '';
    $confirm_password = $_POST['confirm_password'] ?? '';
    
    if (empty($password) || empty($confirm_password)) {
        $error = 'All fields are required';
    } elseif ($password !== $confirm_password) {
        $error = 'Passwords do not match';
    } elseif (strlen($password) < 8) {
        $error = 'Password must be at least 8 characters';
    } else {
        if (resetPassword($token, $password)) {
            $success = 'Password has been reset successfully! You can now log in with your new password.';
        } else {
            $error = 'Invalid or expired reset token';
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reset Password - Leafboard</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="min-h-screen bg-white flex items-center justify-center p-4">
    <div class="w-full max-w-md">
        <div class="flex items-center gap-2 mb-1">
            <svg class="w-5 h-5" viewBox="0 0 24 24" fill="none">
                <path d="M12 2L2 7L12 12L22 7L12 2Z" fill="#4ADE80" fillOpacity="0.5"/>
                <path d="M12 12L2 7L12 2L22 7L12 12Z" fill="#4ADE80"/>
            </svg>
            <h1 class="text-xl font-semibold">Leafboard</h1>
        </div>
        <p class="text-sm text-gray-600 mb-8">Choose a new password</p>

        <?php if ($error): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <?php echo htmlspecialchars($error); ?>
            </div>
        <?php endif; ?>

        <?php if ($success): ?>
            <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
                <?php echo htmlspecialchars($success); ?>
            </div>
        <?php else: ?>
            <form method="POST" class="space-y-4">
                <div>
                    <label class="block text-sm mb-2">New password</label>
                    <input
                        type="password"
                        name="password"
                        required
                        class="w-full p-4 rounded-xl border border-gray-200"
                        placeholder="min. 8 characters"
                    >
                </div>
                
                <div>
                    <label class="block text-sm mb-2">Confirm new password</label>
                    <input
                        type="password"
                        name="confirm_password"
                        required
                        class="w-full p-4 rounded-xl border border-gray-200"
                        placeholder="min. 8 characters"
                    >
                </div>
                
                <button
                    type="submit"
                    class="w-full p-6 rounded-xl font-medium bg-[#4ADE80] hover:bg-[#22C55E] text-black"
                >
                    Reset Password
                </button>
            </form>
        <?php endif; ?>
        
        <?php if ($success): ?>
            <div class="mt-4">
                <a href="login.php" class="block text-center text-sm text-[#4ADE80]">
                    Go to Login
                </a>
            </div>
        <?php endif; ?>
    </div>
</body>
</html>