-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.php
50 lines (45 loc) · 1.48 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Created by PhpStorm.
* User: larry.kluger
* Date: 11/21/18
* Time: 8:46 PM
*/
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../vendor/docusign/esign-client/autoload.php';
require_once __DIR__ . '/../ds_config.php';
use DocuSign\Services\RouterService;
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$GLOBALS['app_url'] = $GLOBALS['DS_CONFIG']['app_url'] . '/';
$loader = new Twig\Loader\FilesystemLoader(__DIR__ . '/../templates');
$twig = new Twig\Environment($loader);
$twig->addGlobal('app_url', $GLOBALS['app_url']);
$twig->addGlobal('session', $_SESSION);
$twig_function = new Twig\TwigFunction('get_flash', function () {
if (! isset($_SESSION['flash'])) {
$_SESSION['flash'] = [];
}
$msgs = $_SESSION['flash'];
$_SESSION['flash'] = [];
return $msgs;
});
$twig->addFunction($twig_function);
# Add csrf_token func. See https://stackoverflow.com/a/31683058/64904
$twig_function = new Twig\TwigFunction('csrf_token', function ($lock_to = null) {
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
if (empty($_SESSION['csrf_token2'])) {
$_SESSION['csrf_token2'] = random_bytes(32);
}
if (empty($lock_to)) {
return $_SESSION['csrf_token'];
}
return hash_hmac('sha256', $lock_to, $_SESSION['csrf_token2']);
});
$twig->addFunction($twig_function);
$GLOBALS['twig'] = $twig;
$router = new RouterService();
$router->router();