%PDF- %PDF-
| Direktori : /data/www_bck/varak.net_bck/suiteshooters.varak.net/ |
| Current File : //data/www_bck/varak.net_bck/suiteshooters.varak.net/bootstrap.php |
<?php
/**
* Created by PhpStorm.
* User: waritko
* Date: 3.5.16
* Time: 20:36
*/
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/lib/googleClient');
require_once "lib/dibi.min.php";
require_once "lib/smarty/Smarty.class.php";
require_once "nette.phar";
function url(){
$pu = parse_url($_SERVER['REQUEST_URI']);
return $pu["scheme"] . "://" . $pu["host"];
}
dibi::connect(array(
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'suiteshooters',
'password' => '6dMEYDjnNR5rjBEp',
'database' => 'suiteshooters',
'charset' => 'utf8',
'profiler' => [
'run' => TRUE,
'file' => __DIR__ . '/log/log-' . date('Y-m-d') . '.txt',
],
));
$smarty = new Smarty();
$smarty->setTemplateDir( __DIR__ . '/templates/');
$smarty->setCompileDir( __DIR__ . '/templates_c/');
$smarty->setConfigDir( __DIR__ . '/configs/');
$smarty->setCacheDir( __DIR__ . '/cache/');
$smarty->debugging = false;
$userId = false;
ini_set('session.gc_maxlifetime', 14*24*3600);
session_set_cookie_params(14*24*3600);
session_start();
//Google API PHP Library includes
require_once 'vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfigFile(__DIR__ . '/client_secret_605290507813-bi1u4msh2ps5bl969qdbma18gk2mihp1.apps.googleusercontent.com.json');
$client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$oauth = new Google_Service_Oauth2($client);
if(!isset($_SESSION['userId']))
{
//var_dump($oauth->userinfo->get());
$gid = $oauth->userinfo->get()->id;
$mail = $oauth->userinfo->get()->email;
$name = $oauth->userinfo->get()->name;
$id = dibi::query("SELECT [id] FROM [users] WHERE [googleId]=%s", $gid)->fetchSingle();
if(!$id)
{
$data = array(
'googleId' => $gid,
'mail' => $mail,
'userMail' => $mail,
'name' => $name,
'isAdmin' => 0,
'calendarToken' => trim(file_get_contents('/proc/sys/kernel/random/uuid')),
);
dibi::query("INSERT INTO [users]", $data);
$_SESSION['userId'] = dibi::insertId();
$_SESSION['isAdmin'] = false;
}
else
{
$_SESSION['userId'] = $id;
$res = dibi::query("SELECT [isAdmin] FROM [users] WHERE [id]=%i", $id)->fetch();
$_SESSION['isAdmin'] = boolval($res->isAdmin);
}
}
$userId = $_SESSION['userId'];
if(!isset($_SESSION['calendarToken']))
{
$_SESSION['calendarToken'] = dibi::query("SELECT [calendarToken] FROM [users] WHERE [id]=%i", $userId)->fetchSingle();
}
}
else
{
$redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
$smarty->assign('session', $_SESSION);
$smarty->assign('userId', $userId);
$smarty->assign('queryString', $_SERVER['QUERY_STRING']);
$smarty->assign('baseUrl', 'https://' . $_SERVER['SERVER_NAME']);
$smarty->assign('calendarToken', $_SESSION['calendarToken']);