<?php

$account = null;

function loadAccountData()
{
    global $account;

    if (!$account && isset($_SESSION["accountId"]))
        $account = Account::LoadId($_SESSION["accountId"]);
}

function login()
{
    global $account;

    if (isset($_POST["accountName"]) && isset($_POST["accountPassword"]))
    {
        // try login
        $account = Account::LoadWithCredentials($_POST["accountName"], $_POST["accountPassword"]);
        if ($account)
        {
            $_SESSION["accountId"] = $account->getId();
            header("Location: ./");
            exit;
        }
    }
    return false;
}

