|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The PHP Skeleton App |
|
4
|
|
|
* |
|
5
|
|
|
* @author Goran Halusa <[email protected]> |
|
6
|
|
|
* @copyright 2015 Goran Halusa |
|
7
|
|
|
* @link https://github.com/ghalusa/PHP-Skeleton-App |
|
8
|
|
|
* @license https://github.com/ghalusa/PHP-Skeleton-App/wiki/License |
|
9
|
|
|
* @version 0.1.1 |
|
10
|
|
|
* @package PHP Skeleton App |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
13
|
|
|
* file that was distributed with this source code. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Register Account |
|
18
|
|
|
* |
|
19
|
|
|
* Class for registering accounts. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Goran Halusa <[email protected]> |
|
22
|
|
|
* @since 0.1.0 |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace PHPSkeleton; |
|
26
|
|
|
use PDO; |
|
27
|
|
|
|
|
28
|
|
|
class RegisterAccount |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var string|bool $session_key The session key |
|
32
|
|
|
*/ |
|
33
|
|
|
private $session_key = false; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var object $db The database connection object |
|
37
|
|
|
*/ |
|
38
|
|
|
public $db; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor |
|
42
|
|
|
* @param object $db_connection The database connection object |
|
43
|
|
|
* @param string $session_key The session key |
|
44
|
|
|
*/ |
|
45
|
|
View Code Duplication |
public function __construct( $db_connection = false, $session_key = false ) |
|
46
|
|
|
{ |
|
47
|
|
|
if ($db_connection && is_object($db_connection)) { |
|
48
|
|
|
$this->db = $db_connection; |
|
49
|
|
|
} |
|
50
|
|
|
$this->session_key = $session_key; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Account Email Exists |
|
55
|
|
|
* |
|
56
|
|
|
* Run a query to determine if a user account email exists in the database. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $user_account_email The data value |
|
59
|
|
|
* @return false|string The query result |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
public function account_email_exists( $user_account_email ) |
|
62
|
|
|
{ |
|
63
|
|
|
$statement = $this->db->prepare("SELECT |
|
64
|
|
|
user_account_id |
|
65
|
|
|
,user_account_email |
|
66
|
|
|
FROM user_account |
|
67
|
|
|
WHERE user_account_email = :user_account_email"); |
|
68
|
|
|
$statement->bindValue(":user_account_email", $user_account_email, PDO::PARAM_INT); |
|
69
|
|
|
$statement->execute(); |
|
70
|
|
|
return $statement->fetch(PDO::FETCH_ASSOC); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Is Registered |
|
75
|
|
|
* |
|
76
|
|
|
* Run a query to determine if a user account has been registered. |
|
77
|
|
|
* |
|
78
|
|
|
* @param int $user_account_id The data value |
|
79
|
|
|
* @return array|bool The query result |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
public function is_registered( $user_account_id ) |
|
82
|
|
|
{ |
|
83
|
|
|
$statement = $this->db->prepare("SELECT user_account.acceptable_use_policy |
|
84
|
|
|
,GROUP_CONCAT(user_account_groups.group_id SEPARATOR ', ') AS groups |
|
85
|
|
|
FROM user_account |
|
86
|
|
|
LEFT JOIN user_account_groups ON user_account.user_account_id = user_account_groups.user_account_id |
|
87
|
|
|
WHERE user_account.user_account_id = :user_account_id |
|
88
|
|
|
AND user_account.acceptable_use_policy = 1 |
|
89
|
|
|
GROUP BY user_account.user_account_id |
|
90
|
|
|
HAVING groups != ''"); |
|
91
|
|
|
$statement->bindValue(":user_account_id", $user_account_id, PDO::PARAM_INT); |
|
92
|
|
|
$statement->execute(); |
|
93
|
|
|
return $statement->fetch(PDO::FETCH_ASSOC); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Update Emailed Hash |
|
98
|
|
|
* |
|
99
|
|
|
* Run a query to update an emailed hash. |
|
100
|
|
|
* |
|
101
|
|
|
* @param int $user_account_id The data value |
|
102
|
|
|
* @param string $emailed_hash The data value |
|
103
|
|
|
* @return null|boolean The query result |
|
104
|
|
|
*/ |
|
105
|
|
|
public function update_emailed_hash( $user_account_id = false, $emailed_hash = false ) |
|
106
|
|
|
{ |
|
107
|
|
|
$updated = false; |
|
108
|
|
View Code Duplication |
if ($user_account_id && $emailed_hash) { |
|
|
|
|
|
|
109
|
|
|
// UPDATE the emailed_hash in the user_account table. |
|
110
|
|
|
$statement = $this->db->prepare("UPDATE user_account |
|
111
|
|
|
SET emailed_hash = :emailed_hash, active = 0 |
|
112
|
|
|
WHERE user_account_id = :user_account_id"); |
|
113
|
|
|
$statement->bindValue(":emailed_hash", $emailed_hash, PDO::PARAM_STR); |
|
114
|
|
|
$statement->bindValue(":user_account_id", $user_account_id, PDO::PARAM_INT); |
|
115
|
|
|
$statement->execute(); |
|
116
|
|
|
$error = $this->db->errorInfo(); |
|
117
|
|
|
if ($error[0] != "00000") { |
|
118
|
|
|
die('The UPDATE user_account emailed_hash query failed.'); |
|
119
|
|
|
} |
|
120
|
|
|
$updated = true; |
|
121
|
|
|
} |
|
122
|
|
|
return $updated; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Update Password |
|
127
|
|
|
* |
|
128
|
|
|
* Run a query to update a password. |
|
129
|
|
|
* |
|
130
|
|
|
* @param int $user_account_password The data value |
|
131
|
|
|
* @param int $user_account_id The data value |
|
132
|
|
|
* @param string $emailed_hash The data value |
|
133
|
|
|
* @return null|boolean True/False |
|
134
|
|
|
*/ |
|
135
|
|
|
public function update_password( $user_account_password = false, $user_account_id = false, $emailed_hash = false ) |
|
136
|
|
|
{ |
|
137
|
|
|
$updated = false; |
|
138
|
|
View Code Duplication |
if ($user_account_id && $emailed_hash) { |
|
|
|
|
|
|
139
|
|
|
// UPDATE the emailed_hash in the user_account table. |
|
140
|
|
|
$statement = $this->db->prepare("UPDATE user_account |
|
141
|
|
|
SET user_account_password = :user_account_password, active = 1 |
|
142
|
|
|
WHERE user_account_id = :user_account_id |
|
143
|
|
|
AND emailed_hash = :emailed_hash"); |
|
144
|
|
|
$statement->bindValue(":user_account_password", $user_account_password, PDO::PARAM_STR); |
|
145
|
|
|
$statement->bindValue(":user_account_id", $user_account_id, PDO::PARAM_INT); |
|
146
|
|
|
$statement->bindValue(":emailed_hash", $emailed_hash, PDO::PARAM_STR); |
|
147
|
|
|
$statement->execute(); |
|
148
|
|
|
$error = $this->db->errorInfo(); |
|
149
|
|
|
if ($error[0] != "00000") { |
|
150
|
|
|
die('The UPDATE user_account password query failed.'); |
|
151
|
|
|
} |
|
152
|
|
|
$updated = true; |
|
153
|
|
|
} |
|
154
|
|
|
return $updated; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: