Subversion Repository Public Repository

Nextrek

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
<?php
    header("Access-Control-Allow-Origin: *");
    header('Content-Type: application/json; charset=UTF-8');

    require_once("constants.php");
    
	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=".DB_SERVERNAME.";dbname=".DB_NAME, DB_USERNAME, DB_PASSWORD);
    	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    	//echo "Connesso con successo al DB";

        if (!array_key_exists("user_id", $params) || $params["user_id"] === "") {
            $risposta = createErrorMessage(-1, "Parametro \"username\" non valido o mancante");
            echo json_encode($risposta);
            die();
        }

        //if (!array_key_exists("token", $params) || !UserRepository::checkToken($params["token"], $conn)) {
        if (!array_key_exists("token", $params) || $params["token"] === "" ||
            !UserRepository::checkUserByToken($params["user_id"], $params["token"], $conn) ||
            !UserRepository::checkAdminByToken($params["token"], $conn)) {
            $risposta = createErrorMessage(-1, "Token non valido");
            //$risposta["return"] = -1;
            echo json_encode($risposta);
            die();
        }
        
    	$user_repo = new UserRepository($conn);

    	$user->id 		        = $params["user_id"];
		//$user->nome		= array_key_exists("nome", $params) ? $params["nome"] : null;
        $user->nome             = array_key_exists("nome", $params) ? $params["nome"] : null;
        $user->cognome          = array_key_exists("cognome", $params) ? $params["cognome"] : 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 = createErrorMessage(1, "Errore DB");
   		//$risposta["return"] = 1;
    }

    echo json_encode($risposta);
	$conn = null; //Close the connection to the DBMS

?>

Commits for Nextrek/Android/SmartCharging/endPoints/nightly/edit_utente.php

Diff revisions: vs.
Revision Author Commited Message
725 Diff Diff FSallustio picture FSallustio Wed 09 Sep, 2015 07:51:47 +0000

Gestione utenze admin in SC

723 Diff Diff FSallustio picture FSallustio Tue 08 Sep, 2015 15:05:25 +0000

Aggiunto check sull’associazione tra utente e token.

537 Diff Diff FSallustio picture FSallustio Mon 24 Aug, 2015 14:46:21 +0000
517 Diff Diff FSallustio picture FSallustio Thu 20 Aug, 2015 14:25:03 +0000
508 Diff Diff FSallustio picture FSallustio Thu 20 Aug, 2015 08:43:10 +0000
469 Diff Diff FSallustio picture FSallustio Mon 03 Aug, 2015 13:53:11 +0000
467 FSallustio picture FSallustio Mon 03 Aug, 2015 13:36:12 +0000

edit_locale.php e edit_utente.php