-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
89 lines (73 loc) · 2.34 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
// Session management
session_start();
// Use space
use Medoo\Medoo;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
// Include composer
require 'vendor/autoload.php';
// Helper functions
function is_loggedin()
{
if ( empty($_SESSION['role']) )
{
header("Location: /#");
exit();
}
}
// Define new app
$app = new \Slim\App;
#$app->config('debug', true);
// Fetch DI Container
$container = $app->getContainer();
// Register Twig View helper
$container['db'] = function () {
$database = new Medoo([
#'database_type' => 'sqlite',
#'database_file' => 'store.db'
'database_type' => 'mysql',
'database_name' => 'agile2_bd',
'server' => 'localhost',
'username' => 'root',
'password' => ''
]);
return $database;
};
// Register Twig View helper
$container['view'] = function ($c) {
$view = new \Slim\Views\Twig('templates', [
//'cache' => 'path/to/cache'
]);
// Instantiate and add Slim specific extension
$router = $c->get('router');
$uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER));
$view->addExtension(new \Slim\Views\TwigExtension($router, $uri));
return $view;
};
$app->get('/', function (Request $request, Response $response, array $args) {
is_loggedin();
return $this->view->render($response, 'dashboard.html', [
'session' => $_SESSION
]);
});
$app->get('/#', function (Request $request, Response $response, array $args) {
if ( !empty($_SESSION['role']) )
{
header("Location: /");
exit();
}
return $this->view->render($response, 'login.html');
});
$app->get('/addAbsence', function (Request $request, Response $response, array $args) {
is_loggedin();
return $this->view->render($response, 'addAbsence.html', [
'session' => $_SESSION
]);
});
$app->get('/logout', function (Request $request, Response $response, array $args) {
session_destroy();
header("Location: /#");
exit();
});
$app->run();