

Nextrek
@ 469
Nextrek / Android / SmartCharging / endPoints / nightly / edit_utente.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 |
<?php header("Access-Control-Allow-Origin: *"); header('Content-Type: application/json; charset=UTF-8'); require_once("repositories/UserRepository.php"); require_once("classes/User.php"); $servername = "localhost"; $username = "smartcharging"; $password = "LXRLBaEAuRr7M7jY"; //$params = json_decode($_REQUEST["params"], true); //$input = file_get_contents('php://input'); $params = json_decode(file_get_contents('php://input'), true); $conn; $user = new User(); $user_repo; //var_dump($params); try { $conn = new PDO("mysql:host=".$servername.";dbname=smartcharging", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //echo "Connesso con successo al DB"; if (!array_key_exists("token", $params) || !UserRepository::checkToken($params["token"], $conn)) { $risposta["return"] = -1; echo json_encode($risposta); die(); } $user_repo = new UserRepository($conn); $user->id = $params["user_id"]; $user->nominativo = array_key_exists("nominativo", $params) ? $params["nominativo"] : null; $user->cell = array_key_exists("cell", $params) ? $params["cell"] : null; $user->email = array_key_exists("email", $params) ? $params["email"] : null; $risposta = $user_repo->editUser($user); } catch(PDOException $e) { echo $e->getMessage(); $risposta["return"] = 1; } echo json_encode($risposta); $conn = null; //Close the connection to the DBMS ?> |