-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-users.php
132 lines (108 loc) · 3.33 KB
/
admin-users.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
use \Hcode\PageAdmin;
use \Hcode\Model\User;
$app->get("/admin/users/:iduser/password", function($iduser) {
User::verifyLogin();
$user = new User();
$user->get((int)$iduser);
$page = new PageAdmin();
$page->setTpl("users-password", [
"user"=>$user->getValues(),
"msgError"=>User::getMsgError(),
"msgSuccess"=>User::getMsgSuccess()
]);
});
$app->post("/admin/users/:iduser/password", function($iduser) {
User::verifyLogin();
if (!isset($_POST["despassword"]) || $_POST["despassword"] === "") {
User::setMsgError("Preencha a nova senha.");
header("Location: /admin/users/$iduser/password");
exit;
}
if (!isset($_POST["despassword-confirm"]) || $_POST["despassword-confirm"] === "") {
User::setMsgError("Preencha a confirmação da nova senha.");
header("Location: /admin/users/$iduser/password");
exit;
}
if ($_POST["despassword"] !== $_POST["despassword-confirm"]) {
User::setMsgError("Confirme corretamente as senhas.");
header("Location: /admin/users/$iduser/password");
exit;
}
$user = new User();
$user->get((int)$iduser);
$user->setPassword(User::getPasswordHash($_POST["despassword"]));
User::setMsgSuccess("Senha alterada com sucesso.");
header("Location: /admin/users/$iduser/password");
exit;
});
$app->get('/admin/users', function() {
User::verifyLogin();
$search = (isset($_GET["search"])) ? $_GET["search"] : "";
$page = (isset($_GET["page"])) ? (int)$_GET["page"] : 1;
if ($search != "") {
$pagination = User::getPageSearch($search, $page);
} else {
$pagination = User::getPage($page);
}
$pages = [];
for ($x=0; $x < $pagination["pages"]; $x++) {
array_push($pages, [
"href"=>"/admin/users?" . http_build_query([
"page"=>$x+1,
"search"=>$search
]),
"text"=>$x+1
]);
}
$page = new PageAdmin();
$page->setTpl("users", array(
"users"=>$pagination["data"],
"search"=>$search,
"pages"=>$pages
));
});
$app->get('/admin/users/create', function() {
User::verifyLogin();
$page = new PageAdmin();
$page->setTpl("users-create");
});
$app->get("/admin/users/:iduser/delete", function($iduser) {
User::verifyLogin();
$user = new User();
$user->get((int)$iduser);
$user->delete();
header("Location: /admin/users");
exit;
});
$app->get('/admin/users/:iduser', function($iduser) {
User::verifyLogin();
$user = new User();
$user->get((int)$iduser);
$page = new PageAdmin();
$page ->setTpl("users-update", array(
"user"=>$user->getValues()
));
});
$app->post("/admin/users/create", function() {
User::verifyLogin();
$user = new User();
$_POST["inadmin"] = (isset($_POST["inadmin"]))?1:0;
$user->setData($_POST);
$user->save();
// $password = password_hash($_POST["despassword"], PASSWORD_DEFAULT, ["cost"=>12]);
// $user->setPassword($password);
header("Location: /admin/users");
exit;
});
$app->post("/admin/users/:iduser", function($iduser) {
User::verifyLogin();
$user = new User();
$_POST["inadmin"] = (isset($_POST["inadmin"]))?1:0;
$user->get((int)$iduser);
$user->setData($_POST);
$user->update();
header("Location: /admin/users");
exit;
});
?>