<?php
    session_start();

    require_once 'config.php';
    require_once 'admin_auth.php';

    if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['admin_login'])) {
        $admin_username = $_POST['admin_username'];
        $admin_password = $_POST['admin_password'];

        $admin = authenticateAdmin($admin_username, $admin_password, $pdo);

        if($admin['username'] === $admin_username && $admin['password'] === $admin_password)
        {
            $_SESSION['admin_username'] = $admin['username'];
            header("Location: index.php");
            exit;
        } else {
            header("Location: login.php");
            exit;
        }
    }
?>
