/
ControleRota.php
103 lines (82 loc) · 3.44 KB
/
ControleRota.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Controllers;
require_once __DIR__ . '/../Library/cypher3des.php';
use Respect\Rest\Router;
use Controllers\ControleUsuario;
use Models\Usuario;
use Library\Container;
use Viewers\Inicial;
/**
* Description of ControleRota
*
* @author adenilton
*/
class ControleRota {
protected $router;
public function __construct() {
$myRouter = Container::getRouter();
$this->pageDefault($myRouter);
$this->pageChat($myRouter);
$this->postCadUser($myRouter);
$this->postLoginUser($myRouter);
}
public function pageChat(Router $r) {
$r->get("/chat", function() {
$fs = Container::getTwigLoderFileSystem(__DIR__ . "/../../public/");
$options = ["auto_reload" => true, "cache" => __DIR__ . "/../../public/cache"];
$twig = Container::getTwigEnvironment($fs, $options);
$index = new Inicial($twig);
$index->exibir('chat.html');
});
}
public function pageDefault(Router $r) {
$r->get("/", function() {
$fs = Container::getTwigLoderFileSystem(__DIR__ . "/../../public/");
$options = ["auto_reload" => true, "cache" => __DIR__ . "/../../public/cache"];
$twig = Container::getTwigEnvironment($fs, $options);
$index = new Inicial($twig);
$index->exibir('default.html');
});
}
public function postCadUser(Router $r) {
$r->post('/ajax/ControleUsuario/cadastrar/**', function($uinfo){
// lê o conteúdo do arquivo para uma string
$json_str = file_get_contents("/var/www/minichat3des/public/js/srp.json");
$jsrc = json_decode($json_str, true);
extract($jsrc);
$ud = array(
"email" => mcrypt_decrypt(MCRYPT_3DES, $k, hexToString($uinfo[0]), MCRYPT_MODE_CBC, hexToString($iv)),
"nome" => mcrypt_decrypt(MCRYPT_3DES, $k, hexToString($uinfo[1]), MCRYPT_MODE_CBC, hexToString($iv)),
"sobrenome" => mcrypt_decrypt(MCRYPT_3DES, $k, hexToString($uinfo[2]), MCRYPT_MODE_CBC, hexToString($iv)),
"apelido" => mcrypt_decrypt(MCRYPT_3DES, $k, hexToString($uinfo[3]), MCRYPT_MODE_CBC, hexToString($iv)),
"senha" => $uinfo[4]
);
$em = Container::gerEntityManager();
$c = new ControleUsuario($em);
$us = new Usuario();
$c->cadastrar($us, $ud);
unset($c, $us);
});
}
public function postLoginUser(Router $r) {
$r->post('/ajax/ControleUsuario/login/*/*', function($email, $senha) {
$em = Container::gerEntityManager();
$c = new ControleUsuario($em);
$json_str = file_get_contents("/var/www/minichat3des/public/js/srp.json");
$jsrc = json_decode($json_str, true);
extract($jsrc);
$login = array(
"email" => mcrypt_decrypt(MCRYPT_3DES, $k, hexToString($email), MCRYPT_MODE_CBC, hexToString($iv)),
"senha" => $senha
);
$rsp = $c->login($login);
if($rsp){
header("/chat");
}
});
}
public function getValidarUsuario(Router $r) {
$r->get("/ControleUsuario/validar/*/*/*", function ($email, $fullname, $nick) {
});
}
}