<?php $app = require '../app/inc.php';

if ($app->user->logged_in)
{
    $app->redirect('index.php');
}

$username = (string)filter_input(INPUT_POST, 'username');
$password = (string)filter_input(INPUT_POST, 'password');

if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
    if ($app->user->login($username, $password))
    {
        $app->session->flash("Velkommen {$username}!");
        $app->redirect('index.php');
    }
    http_response_code(401);
    $app->session->flash('Feil påloggingsinformasjon', 'danger');
}

$app->view('template/header', ["title" => "Logg inn"]);
$app->view('pages/login');
$app->view('template/footer');