<?php

require_once "UserDAO.php";
require_once "User.php";
require_once "functions.php";
$message = "";
if (checkSession()) {
    redirect_to("admin.php");
}
if (isset($_POST["username"]) && isset($_POST["password"])) {
    try {
        $user = new User();
        $user->username = $_POST["username"];
        $user->password = $_POST["password"];
        if (UserDAO::validateUser($user) == true) {
            createSession($user->username);
            redirect_to("index.php");
        } else {
            $message = "invalid username / password";
        }
    } catch (Exception $exception) {
        echo $exception;
        die;
    }
}
include "partials/header.php";
?>

<div class="container" style="padding-top:200px;">
<div class="row">
<h2 align="center">Login</h2>