<?php

include_once '../bootstrap.php';
use Models\LoginManager;
use Views\LoginView;
LoginManager::startSession();
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    $loginView = new LoginView(false);
    $loginView->render();
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $loginManager = new LoginManager();
    $isLoginSuccess = $loginManager->isValid($username, $password);
    if ($isLoginSuccess) {
        header("Location: /auction/homepage");
        exit;
    } else {
        $loginView = new LoginView(true);
        $loginView->render();
    }
}