<?php

include 'Services/Twilio.php';
require "config.php";
require "system/jolt.php";
require "system/pdo.class.php";
require "system/functions.php";
$_GET['route'] = isset($_GET['route']) ? '/' . $_GET['route'] : '/';
$app = new Jolt('site', false);
$app->option('source', 'config.ini');
#$pdo = Db::singleton();
$mysiteURL = $app->option('site.url');
//      Conditions      --------------------------------------------------------------------------------------------
$app->condition('signed_in', function () use($app) {
    $app->redirect($app->getBaseUri() . '/login', !$app->store('user'));
});
//      Login   --------------------------------------------------------------------------------------------
$app->get('/login', function () use($app) {
    $app->render('login', array(), 'layout');
});
$app->post('/login', function () use($app) {
    $sql = "SELECT * FROM `user` WHERE `email`='{$_POST['user']}' AND `password`='{$_POST['pass']}'";
    $pdo = Db::singleton();
    $res = $pdo->query($sql);
    $user = $res->fetch();
    if (isset($user['ID'])) {
        $app->store('user', $user['ID']);
        $app->redirect($app->getBaseUri() . '/home');
    } else {
        $app->redirect($app->getBaseUri() . '/login');
    }