-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
62 lines (49 loc) · 1.65 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
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
session_set_save_handler (new \Echosong\RedisSession\RedisSessionHandler ([
'host' => '127.0.0.1'
,'port' => 6379
,'timeout' => 2
,'database' => 0
,'prefix' => 'redis_session'
]), true);
$configuration = [
'settings' => [
'displayErrorDetails' => true,
],
];
$c = new \Slim\Container($configuration);
$app = new \Slim\App($c);
$app->add(new \Slim\Middleware\Session([
'name' => 'dummy_session',
'autorefresh' => true,
'lifetime' => '1 hour'
]));
$container = $app->getContainer();
// Register component on container
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('views', []);
return $view;
};
$container['session'] = function ($container) {
return new \SlimSession\Helper;
};
$app->get('/logar', function (Request $request, Response $response, array $args) {
return $this->view->render ($response, 'logar.html', []);
});
$app->post('/efetuarlogon', function (Request $request, Response $response, array $args) {
$parsedBody = $request->getParsedBody ();
$this->session['nome'] = $parsedBody['nome'];
return $response->withRedirect ('dadoslogin', 301);
});
$app->get('/dadoslogin', function (Request $request, Response $response, array $args) {
return $this->view->render ($response, 'dados_login.html', [ 'nome' => $this->session['nome']]);
});
$app->get ('/sair', function (Request $request, Response $response, array $args) {
$this->session::destroy();
return $this->view->render ($response, 'mensagem_de_logoff.html', []);
});
$app->run();
?>