Example #1
0
require_once 'library/Gorilla3d/Template.php';
require_once 'models/Accounts.php';
require_once 'models/Sites.php';
$session = new Gorilla3d_Session();
if ($session->get('accountId') !== null) {
    header('Location: app');
    exit;
}
$error = false;
$password = isset($_POST['password']) ? $_POST['password'] : '';
$username = isset($_POST['username']) ? $_POST['username'] : '';
if (!empty($_POST)) {
    $newAccount = false;
    if (!Accounts::exists()) {
        Accounts::createTable();
        Sites::createTable();
        $newAccount = true;
    }
    $account = false;
    if ($newAccount) {
        $account = new Accounts();
        $account->setPasswd($password)->setUsername($username);
        Accounts::insert($account);
        unset($account);
    }
    $account = Accounts::byLogin($username, $password);
    if ($account === false) {
        $error = 'Unable to Login';
    } else {
        $session->set('accountId', $account->id);
        header('Location: app');