-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_auth_api.php
More file actions
84 lines (71 loc) · 1.87 KB
/
admin_auth_api.php
File metadata and controls
84 lines (71 loc) · 1.87 KB
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
<?php
require_once 'auth_admin.php';
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
exit(0);
}
$input = json_decode(file_get_contents('php://input'), true);
$action = $input['action'] ?? '';
switch ($action) {
case 'login':
adminLogin($input);
break;
case 'logout':
adminLogout();
break;
case 'check_auth':
checkAdminAuth();
break;
default:
echo json_encode([
'sucesso' => false,
'mensagem' => 'Ação não reconhecida.'
]);
break;
}
function adminLogin($input) {
$senha = $input['senha'] ?? '';
if (empty($senha)) {
echo json_encode([
'sucesso' => false,
'mensagem' => 'Senha é obrigatória.'
]);
return;
}
if (loginSuperAdmin($senha)) {
echo json_encode([
'sucesso' => true,
'mensagem' => 'Login realizado com sucesso!'
]);
} else {
echo json_encode([
'sucesso' => false,
'mensagem' => 'Senha incorreta.'
]);
}
}
function adminLogout() {
logoutSuperAdmin();
echo json_encode([
'sucesso' => true,
'mensagem' => 'Logout realizado com sucesso!'
]);
}
function checkAdminAuth() {
if (verificarSuperAdmin()) {
echo json_encode([
'sucesso' => true,
'autenticado' => true,
'csrf_token' => gerarTokenCSRF()
]);
} else {
echo json_encode([
'sucesso' => true,
'autenticado' => false
]);
}
}
?>