Nextrek
Diff Revisions
423
vs
424
for /Android/SmartCharging/endPoints/nightly/upload_avatar.php
|
@@ -3,22 +3,6 @@ |
3 |
3 |
|
require_once("repositories/UserRepository.php"); |
4 |
4 |
|
require_once("constants.php"); |
5 |
5 |
|
|
6 |
|
- |
if (!array_key_exists("user_id", $_POST) || !array_key_exists("avatar_name", $_POST)) { |
7 |
|
- |
$risposta["return"] = 1; |
8 |
|
- |
$risposta["avatar_name"] = ""; |
9 |
|
- |
echo json_encode($risposta); |
10 |
|
- |
die(); |
11 |
|
- |
} |
12 |
|
- |
|
13 |
|
- |
if(isset($_FILES['avatar_file'])) |
14 |
|
- |
{ |
15 |
|
- |
$file = $_FILES['avatar_file']; |
16 |
|
- |
if($file['error'] == UPLOAD_ERR_OK and is_uploaded_file($file['tmp_name'])) |
17 |
|
- |
{ |
18 |
|
- |
move_uploaded_file($file['tmp_name'], $_SERVER['DOCUMENT_ROOT'].AVATAR_PATH.$_POST["avatar_name"]); |
19 |
|
- |
} |
20 |
|
- |
} |
21 |
|
- |
|
22 |
6 |
|
$servername = "localhost"; |
23 |
7 |
|
$username = "smartcharging"; |
24 |
8 |
|
$password = "LXRLBaEAuRr7M7jY"; |
|
@@ -32,6 +16,28 @@ |
32 |
16 |
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
33 |
17 |
|
//echo "Connesso con successo al DB"; |
34 |
18 |
|
|
|
19 |
+ |
if (!array_key_exists("token", $_POST) || !UserRepository::checkToken($_POST["token"], $conn)) { |
|
20 |
+ |
$risposta["return"] = -1; |
|
21 |
+ |
echo json_encode($risposta); |
|
22 |
+ |
die(); |
|
23 |
+ |
} |
|
24 |
+ |
|
|
25 |
+ |
if (!array_key_exists("user_id", $_POST) || !array_key_exists("avatar_name", $_POST)) { |
|
26 |
+ |
$risposta["return"] = 1; |
|
27 |
+ |
$risposta["avatar_name"] = ""; |
|
28 |
+ |
echo json_encode($risposta); |
|
29 |
+ |
die(); |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
if(isset($_FILES['avatar_file'])) |
|
33 |
+ |
{ |
|
34 |
+ |
$file = $_FILES['avatar_file']; |
|
35 |
+ |
if($file['error'] == UPLOAD_ERR_OK and is_uploaded_file($file['tmp_name'])) |
|
36 |
+ |
{ |
|
37 |
+ |
move_uploaded_file($file['tmp_name'], $_SERVER['DOCUMENT_ROOT'].AVATAR_PATH.$_POST["avatar_name"]); |
|
38 |
+ |
} |
|
39 |
+ |
} |
|
40 |
+ |
|
35 |
41 |
|
$user_repo = new UserRepository($conn); |
36 |
42 |
|
$risposta = $user_repo->setAvatar($_POST["user_id"], $_POST["avatar_name"]); |
37 |
43 |
|
|