Nextrek
Diff Revisions
353
vs
354
for /Android/SmartCharging/endPoints/UserRepository.php
|
@@ -51,6 +51,32 @@ |
51 |
51 |
|
|
52 |
52 |
|
} |
53 |
53 |
|
|
|
54 |
+ |
public function loginUser($username, $password) { |
|
55 |
+ |
$status = array(); |
|
56 |
+ |
|
|
57 |
+ |
try { |
|
58 |
+ |
$query = "SELECT id, password FROM utente WHERE username='".$username."'"; |
|
59 |
+ |
$result = $this->db->query($query); |
|
60 |
+ |
$row = ($result->rowCount()>0) ? $result->fetch() : null; |
|
61 |
+ |
|
|
62 |
+ |
if (!is_null($row) && password_verify($password, $row["password"])) { |
|
63 |
+ |
$status["return"] = 0; |
|
64 |
+ |
$status["id"] = $row["id"]; |
|
65 |
+ |
} else { |
|
66 |
+ |
$status["return"] = 1; |
|
67 |
+ |
$status["id"] = -1; |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
return $status; |
|
71 |
+ |
|
|
72 |
+ |
} catch (PDOException $e) { |
|
73 |
+ |
echo $e->getMessage(); |
|
74 |
+ |
$status["return"] = 2; |
|
75 |
+ |
$status["id"] = -1; |
|
76 |
+ |
return $status; |
|
77 |
+ |
} |
|
78 |
+ |
} |
|
79 |
+ |
|
54 |
80 |
|
//true se username è disponibile, false altrimenti |
55 |
81 |
|
protected function checkUserName($user) { |
56 |
82 |
|
$query = "SELECT count(*) from utente WHERE username='".$user->username."'"; |