Nextrek
Diff Revisions
224
vs
235
for /Android/SmartCharging/endPoints/UserRepository.php
|
@@ -9,29 +9,63 @@ |
9 |
9 |
|
} |
10 |
10 |
|
|
11 |
11 |
|
public function registerUser($user, $password) { |
12 |
|
- |
|
13 |
|
- |
$hashedPwd = password_hash($password, PASSWORD_DEFAULT); |
14 |
|
- |
|
15 |
|
- |
$query = "INSERT INTO utente(username, password, nominativo, cell, email, img) |
16 |
|
- |
VALUES ('".$user->username."', |
17 |
|
- |
'".$hashedPwd."', |
18 |
|
- |
'".$user->nominativo."', |
19 |
|
- |
'".$user->cell."', |
20 |
|
- |
'".$user->email."', |
21 |
|
- |
'".$user->img."')"; |
|
12 |
+ |
$status = array(); |
22 |
13 |
|
|
23 |
|
- |
//echo "<br/>".$query."<br/>"; |
24 |
|
- |
|
25 |
14 |
|
try { |
26 |
|
- |
$this->db->exec($query); |
27 |
|
- |
return $this->db->lastInsertId(); |
28 |
15 |
|
|
|
16 |
+ |
if (!$this->checkUserName($user)) { |
|
17 |
+ |
$status["id"] = -1; |
|
18 |
+ |
$status["return"] = 1; |
|
19 |
+ |
return $status; |
|
20 |
+ |
} |
|
21 |
+ |
|
|
22 |
+ |
if (!$this->checkEmail($user)) { |
|
23 |
+ |
$status["id"] = -1; |
|
24 |
+ |
$status["return"] = 2; |
|
25 |
+ |
return $status; |
|
26 |
+ |
} |
|
27 |
+ |
|
|
28 |
+ |
$hashedPwd = password_hash($password, PASSWORD_DEFAULT); |
|
29 |
+ |
|
|
30 |
+ |
$query = "INSERT INTO utente(username, password, nominativo, cell, email, avatar, is_owner) |
|
31 |
+ |
VALUES ('".$user->username."', |
|
32 |
+ |
'".$hashedPwd."', |
|
33 |
+ |
'".$user->nominativo."', |
|
34 |
+ |
'".$user->cell."', |
|
35 |
+ |
'".$user->email."', |
|
36 |
+ |
'".$user->avatar."', |
|
37 |
+ |
'".$user->is_owner."')"; |
|
38 |
+ |
|
|
39 |
+ |
//echo "<br/>".$query."<br/>"; |
|
40 |
+ |
|
|
41 |
+ |
$this->db->exec($query); |
|
42 |
+ |
$status["id"] = $this->db->lastInsertId(); |
|
43 |
+ |
$status["return"] = 0; |
|
44 |
+ |
return $status; |
29 |
45 |
|
//echo "New record created successfully"; |
30 |
46 |
|
} catch (PDOException $e) { |
31 |
47 |
|
echo $e->getMessage(); |
|
48 |
+ |
$status["id"] = -1; |
|
49 |
+ |
$status["return"] = 3; |
|
50 |
+ |
return $status; |
32 |
51 |
|
} |
33 |
52 |
|
|
34 |
53 |
|
} |
|
54 |
+ |
|
|
55 |
+ |
//true se username è disponibile, false altrimenti |
|
56 |
+ |
protected function checkUserName($user) { |
|
57 |
+ |
$query = "SELECT count(*) from utente WHERE username='".$user->username."'"; |
|
58 |
+ |
$result = $this->db->query($query); |
|
59 |
+ |
return ($result->fetchColumn() == "0"); |
|
60 |
+ |
} |
|
61 |
+ |
|
|
62 |
+ |
//true se email è disponibile, false altrimenti |
|
63 |
+ |
protected function checkEmail($user) { |
|
64 |
+ |
$query = "SELECT count(*) from utente WHERE email='".$user->email."'"; |
|
65 |
+ |
$result = $this->db->query($query); |
|
66 |
+ |
return ($result->fetchColumn() == "0"); |
|
67 |
+ |
} |
|
68 |
+ |
|
35 |
69 |
|
} |
36 |
70 |
|
|
37 |
71 |
|
?> |