-
Notifications
You must be signed in to change notification settings - Fork 0
/
impersona.php
50 lines (32 loc) · 1.29 KB
/
impersona.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
<?php
require_once __DIR__ . '/controllers/ErrorHandler.php';
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Content-Type: application/json; charset=UTF-8');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
require_once __DIR__ . '/database.php';
require_once __DIR__ . '/sendJson.php';
require_once __DIR__ . '/controllers/authHandler.php';
//operazioni admin
$authHandler = new AuthHandler();
if ($_SERVER['REQUEST_METHOD'] == 'POST') :
$data = json_decode(file_get_contents('php://input'));
if(isset($data->impersona) && $data->impersona == true){
//se sono in impersona passo
}else{
$authHandler->checkIfAdmin($connection);
}
$id = null;
if(isset($data->id)){
//singolo utente
$id = $data->id;
}
$sql = "SELECT email, extra_info FROM `users` WHERE `id`='$id'";
$query = mysqli_query($connection, $sql);
$row = mysqli_fetch_array($query, MYSQLI_ASSOC);
if ($row === null) sendJson(404, 'User not found!');
$row["password"] = base64_decode($row["extra_info"]);
unset($row["extra_info"]);
sendJson(200, '', $row);
endif;