Subversion Repository Public Repository

Nextrek

Diff Revisions 722 vs 723 for /Android/SmartCharging/endPoints/nightly/repositories/UserRepository.php

Diff revisions: vs.
  @@ -20,7 +20,7 @@
20 20 $this->db = $db;
21 21 }
22 22
23 - public static function checkToken($token, $conn) {
23 + public static function checkToken($token, $conn) { //da rendere deprecata
24 24 try {
25 25 //$queryToken = "SELECT id FROM utente WHERE token='".$token."'";
26 26 $queryToken = "SELECT id FROM utente WHERE token=:token";
  @@ -34,6 +34,49 @@
34 34 }
35 35 }
36 36
37 + public static function checkUserByToken($user_id, $token, $conn) {
38 + try {
39 + //$queryToken = "SELECT id FROM utente WHERE token='".$token."'";
40 + $queryToken = "SELECT id FROM utente WHERE token=:token AND id=:id";
41 + $stmt = $conn->prepare($queryToken);
42 + $stmt->bindParam(':token', $token);
43 + $stmt->bindParam(':id', $user_id);
44 + $result = $stmt->execute();
45 + return ($stmt->rowCount()>0);
46 + } catch (PDOException $e) {
47 + echo $e->getMessage();
48 + return false;
49 + }
50 + }
51 +
52 + public static function checkAdminByToken($token, $conn) {
53 + try {
54 + //$queryToken = "SELECT id FROM utente WHERE token='".$token."'";
55 + $queryToken = "SELECT id FROM utente WHERE token=:token AND is_admin=1";
56 + $stmt = $conn->prepare($queryToken);
57 + $stmt->bindParam(':token', $token);
58 + $result = $stmt->execute();
59 + return ($stmt->rowCount()>0);
60 + } catch (PDOException $e) {
61 + echo $e->getMessage();
62 + return false;
63 + }
64 + }
65 +
66 + public static function getUserByToken($token, $conn) {
67 + try {
68 + //$queryToken = "SELECT id FROM utente WHERE token='".$token."'";
69 + $queryToken = "SELECT id FROM utente WHERE token=:token";
70 + $stmt = $conn->prepare($queryToken);
71 + $stmt->bindParam(':token', $token);
72 + $result = $stmt->execute();
73 + return ($stmt->rowCount()>0) ? $stmt->fetchColumn() : -1;
74 + } catch (PDOException $e) {
75 + echo $e->getMessage();
76 + return -1;
77 + }
78 + }
79 +
37 80 public function registerUser($user, $password) {
38 81 $status = array();
39 82