25 |
- |
1 |
<?php
|
|
|
2 |
// Email sending functions
|
|
|
3 |
include_once 'includes/email_functions.php';
|
|
|
4 |
include_once 'includes/password.php';
|
|
|
5 |
|
31 |
- |
6 |
// Include Session Handling
|
65 |
- |
7 |
require_once ('includes/session.php');
|
122 |
- |
8 |
global $systemConf;
|
|
|
9 |
if (empty($_POST["nonce"]) || NonceUtil::check($systemConf["nonce_secret"], $_POST["nonce"]) === false) {
|
|
|
10 |
// Redirect to the home page
|
|
|
11 |
MySessionHandler::commit(session_id());
|
|
|
12 |
header("Location:../index.php");
|
|
|
13 |
exit;
|
|
|
14 |
}
|
25 |
- |
15 |
|
|
|
16 |
// Include config file
|
|
|
17 |
require_once 'includes/config.php';
|
|
|
18 |
|
|
|
19 |
// Load and initialize user class
|
|
|
20 |
require_once 'includes/User.class.php';
|
|
|
21 |
$user = new User();
|
|
|
22 |
|
65 |
- |
23 |
if (isset($_POST['signupSubmit'])) {
|
|
|
24 |
$valErr = 0;
|
|
|
25 |
$captchaErr = 0;
|
36 |
- |
26 |
|
65 |
- |
27 |
// Store post data into session
|
|
|
28 |
$_SESSION['signup_post_data'] = $_POST;
|
36 |
- |
29 |
|
41 |
- |
30 |
if (!empty($_POST['g-recaptcha-response'])) {
|
|
|
31 |
$secretKey = GR_SECRET_KEY;
|
|
|
32 |
$ch = curl_init('https://www.google.com/recaptcha/api/siteverify?secret=' . $secretKey . '&response=' . $_POST['g-recaptcha-response']);
|
|
|
33 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
65 |
- |
34 |
$verifyResponse = curl_exec($ch);
|
41 |
- |
35 |
$responseData = json_decode($verifyResponse);
|
|
|
36 |
|
65 |
- |
37 |
if ($responseData->success) {
|
41 |
- |
38 |
if ($responseData->score < 0.6) {
|
65 |
- |
39 |
$captchaErr = 1;
|
41 |
- |
40 |
$sessData['status']['type'] = 'error';
|
|
|
41 |
$sessData['status']['msg'] = 'Robot verification failed, please try again.';
|
|
|
42 |
}
|
65 |
- |
43 |
}
|
|
|
44 |
else {
|
|
|
45 |
$captchaErr = 1;
|
41 |
- |
46 |
$sessData['status']['type'] = 'error';
|
|
|
47 |
$sessData['status']['msg'] = 'Robot verification failed, please try again.';
|
|
|
48 |
}
|
65 |
- |
49 |
}
|
|
|
50 |
else {
|
|
|
51 |
$captchaErr = 1;
|
41 |
- |
52 |
$sessData['status']['type'] = 'error';
|
|
|
53 |
$sessData['status']['msg'] = 'Robot verification failed, please try again.';
|
|
|
54 |
}
|
65 |
- |
55 |
|
41 |
- |
56 |
if ($captchaErr == 1) {
|
65 |
- |
57 |
// Redirect back to the registration page
|
41 |
- |
58 |
$_SESSION['sessData'] = $sessData;
|
|
|
59 |
MySessionHandler::commit(session_id());
|
|
|
60 |
header("Location:registration.php");
|
65 |
- |
61 |
exit;
|
41 |
- |
62 |
}
|
|
|
63 |
|
65 |
- |
64 |
// Get user inputs
|
|
|
65 |
$first_name = sanitizeInput($_POST['first_name']);
|
|
|
66 |
$last_name = sanitizeInput($_POST['last_name']);
|
|
|
67 |
$email = sanitizeInput($_POST['email']);
|
|
|
68 |
$zip = sanitizeInput($_POST['zip']);
|
|
|
69 |
$password = sanitizeInput($_POST['password']);
|
|
|
70 |
$confirm_password = sanitizeInput($_POST['confirm_password']);
|
36 |
- |
71 |
|
65 |
- |
72 |
if (empty($first_name)) {
|
|
|
73 |
$valErr = 1;
|
|
|
74 |
$sessData['field_error']['first_name'] = 'Please enter your first name.';
|
|
|
75 |
}
|
|
|
76 |
/*
|
|
|
77 |
if(empty($last_name)){
|
|
|
78 |
$valErr = 1;
|
|
|
79 |
$sessData['field_error']['last_name'] = 'Please enter your last name.';
|
|
|
80 |
}
|
|
|
81 |
*/
|
|
|
82 |
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
|
83 |
$valErr = 1;
|
|
|
84 |
$sessData['field_error']['email'] = 'Please enter a valid email.';
|
|
|
85 |
}
|
|
|
86 |
if (empty($password)) {
|
|
|
87 |
$valErr = 1;
|
|
|
88 |
$sessData['field_error']['password'] = 'Please enter account password.';
|
|
|
89 |
}
|
|
|
90 |
if (empty($confirm_password)) {
|
|
|
91 |
$valErr = 1;
|
|
|
92 |
$sessData['field_error']['confirm_password'] = 'Please confirm your password.';
|
|
|
93 |
}
|
|
|
94 |
elseif ($password !== $confirm_password) {
|
|
|
95 |
$valErr = 1;
|
|
|
96 |
$sessData['field_error']['confirm_password'] = 'Confirm password does not match the password.';
|
|
|
97 |
}
|
25 |
- |
98 |
|
65 |
- |
99 |
if ($valErr == 0) {
|
|
|
100 |
// Check whether user exists in the database
|
|
|
101 |
$cond['where'] = array(
|
|
|
102 |
'email' => $email
|
|
|
103 |
);
|
|
|
104 |
$cond['return_type'] = 'count';
|
|
|
105 |
$userCount = $user->getRows($cond);
|
|
|
106 |
if ($userCount > 0) {
|
|
|
107 |
$sessData['status']['type'] = 'error';
|
|
|
108 |
$sessData['status']['msg'] = 'Email already exists, please use another email.';
|
|
|
109 |
}
|
|
|
110 |
else {
|
|
|
111 |
// Email verification code
|
|
|
112 |
$uniqidStr = md5(uniqid(mt_rand()));
|
36 |
- |
113 |
|
65 |
- |
114 |
// Insert user data in the database
|
|
|
115 |
$userData = array(
|
|
|
116 |
'first_name' => $first_name,
|
|
|
117 |
'last_name' => $last_name,
|
|
|
118 |
'email' => $email,
|
|
|
119 |
'password' => password_hash($password, PASSWORD_DEFAULT) ,
|
|
|
120 |
'zip' => $zip,
|
|
|
121 |
'activation_code' => $uniqidStr
|
|
|
122 |
);
|
|
|
123 |
$insert = $user->insert($userData);
|
36 |
- |
124 |
|
65 |
- |
125 |
// Set status based on data insert
|
|
|
126 |
if ($insert) {
|
|
|
127 |
// Remove post data from session
|
|
|
128 |
unset($_SESSION['signup_post_data']);
|
36 |
- |
129 |
|
65 |
- |
130 |
// Send account verification email
|
|
|
131 |
@emailVerification($userData);
|
36 |
- |
132 |
|
65 |
- |
133 |
$sessData['status']['type'] = 'success';
|
74 |
- |
134 |
$sessData['status']['msg'] = 'Your registration was successful. Please check your email inbox (and spam folder) to verify and activate your account.';
|
36 |
- |
135 |
|
65 |
- |
136 |
// Remove post data from session
|
|
|
137 |
unset($_SESSION['signup_post_data']);
|
|
|
138 |
}
|
|
|
139 |
else {
|
|
|
140 |
$sessData['status']['type'] = 'error';
|
|
|
141 |
$sessData['status']['msg'] = 'Some problem occurred, please try again.';
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
else {
|
25 |
- |
146 |
$sessData['status']['type'] = 'error';
|
36 |
- |
147 |
$sessData['status']['msg'] = 'Please fill all mandatory fields.';
|
25 |
- |
148 |
}
|
|
|
149 |
|
65 |
- |
150 |
// Store signup status into the session
|
25 |
- |
151 |
$_SESSION['sessData'] = $sessData;
|
65 |
- |
152 |
$redirectURL = ($sessData['status']['type'] == 'success') ? 'index.php' : 'registration.php';
|
36 |
- |
153 |
|
65 |
- |
154 |
// Redirect to the home/login page
|
31 |
- |
155 |
MySessionHandler::commit(session_id());
|
65 |
- |
156 |
header("Location:" . $redirectURL);
|
|
|
157 |
exit;
|
|
|
158 |
}
|
|
|
159 |
elseif (isset($_POST['loginSubmit'])) {
|
|
|
160 |
// Get user inputs
|
|
|
161 |
$email = sanitizeInput($_POST['email']);
|
|
|
162 |
$password = sanitizeInput($_POST['password']);
|
36 |
- |
163 |
|
65 |
- |
164 |
// Check whether login details are empty
|
|
|
165 |
if (!empty($email) && !empty($password)) {
|
|
|
166 |
// Get user data from user class
|
25 |
- |
167 |
$conditions['where'] = array(
|
|
|
168 |
'email' => $email,
|
|
|
169 |
'status' => '1'
|
|
|
170 |
);
|
|
|
171 |
$conditions['return_type'] = 'single';
|
|
|
172 |
$userData = $user->getRows($conditions);
|
36 |
- |
173 |
|
65 |
- |
174 |
if (!empty($userData) && password_verify($password, $userData['password'])) {
|
|
|
175 |
// Set user data and status based on login credentials
|
|
|
176 |
if ($userData['activated'] == '0') {
|
|
|
177 |
$sessData['status']['type'] = 'error';
|
|
|
178 |
$sessData['status']['msg'] = 'Your account activation is pending, please check your email inbox to verify and activate your account.';
|
|
|
179 |
}
|
|
|
180 |
else {
|
|
|
181 |
// If remember me is checked
|
|
|
182 |
if (isset($_POST['rememberMe']) && $_POST['rememberMe'] == 1) {
|
|
|
183 |
setcookie('rememberUserId', $userData['id'], time() + (30 * 86400) , "/");
|
|
|
184 |
setcookie('hash', password_hash($userData['password'] . $userData['id'], PASSWORD_DEFAULT) , time() + (30 * 86400) , "/");
|
|
|
185 |
}
|
36 |
- |
186 |
|
65 |
- |
187 |
$sessData['userLoggedIn'] = true;
|
|
|
188 |
$sessData['userID'] = $userData['id'];
|
|
|
189 |
$sessData['status']['type'] = 'success';
|
|
|
190 |
$sessData['status']['msg'] = 'Welcome ' . $userData['first_name'] . '!';
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
else {
|
|
|
194 |
$sessData['status']['type'] = 'error';
|
36 |
- |
195 |
$sessData['status']['msg'] = 'Wrong email or password, please try again.';
|
65 |
- |
196 |
}
|
|
|
197 |
}
|
|
|
198 |
else {
|
25 |
- |
199 |
$sessData['status']['type'] = 'error';
|
36 |
- |
200 |
$sessData['status']['msg'] = 'Enter email and password.';
|
25 |
- |
201 |
}
|
36 |
- |
202 |
|
65 |
- |
203 |
// Store login status into the session
|
25 |
- |
204 |
$_SESSION['sessData'] = $sessData;
|
36 |
- |
205 |
|
65 |
- |
206 |
// Redirect to the home page
|
31 |
- |
207 |
MySessionHandler::commit(session_id());
|
30 |
- |
208 |
header("Location:index.php");
|
65 |
- |
209 |
exit;
|
|
|
210 |
}
|
|
|
211 |
elseif (isset($_POST['forgotSubmit'])) {
|
|
|
212 |
$frmDisplay = '';
|
36 |
- |
213 |
|
65 |
- |
214 |
// Get user inputs
|
|
|
215 |
$email = sanitizeInput($_POST['email']);
|
36 |
- |
216 |
|
65 |
- |
217 |
// Check whether email is empty
|
|
|
218 |
if (!empty($email)) {
|
|
|
219 |
// Check whether user exists in the database
|
|
|
220 |
$cond['where'] = array(
|
|
|
221 |
'email' => $email
|
|
|
222 |
);
|
|
|
223 |
$cond['return_type'] = 'count';
|
|
|
224 |
$userCount = $user->getRows($cond);
|
|
|
225 |
if ($userCount > 0) {
|
|
|
226 |
// Generat unique string
|
|
|
227 |
$uniqidStr = md5(uniqid(mt_rand()));
|
36 |
- |
228 |
|
65 |
- |
229 |
// Update data with forgot pass code
|
|
|
230 |
$conditions = array(
|
|
|
231 |
'email' => $email
|
|
|
232 |
);
|
|
|
233 |
$data = array(
|
|
|
234 |
'forgot_pass_identity' => $uniqidStr
|
|
|
235 |
);
|
|
|
236 |
$update = $user->update($data, $conditions);
|
36 |
- |
237 |
|
65 |
- |
238 |
if ($update) {
|
|
|
239 |
// Get user details
|
|
|
240 |
$con['where'] = array(
|
|
|
241 |
'email' => $email
|
|
|
242 |
);
|
|
|
243 |
$con['return_type'] = 'single';
|
|
|
244 |
$userDetails = $user->getRows($con);
|
36 |
- |
245 |
|
65 |
- |
246 |
// Send reset password email
|
25 |
- |
247 |
@forgotPassEmail($userDetails);
|
36 |
- |
248 |
|
65 |
- |
249 |
$sessData['status']['type'] = 'success';
|
74 |
- |
250 |
$sessData['status']['msg'] = 'Please check your email inbox (and spam folder), we have sent a password reset link to your registered email.';
|
65 |
- |
251 |
$frmDisplay = '?frmDis=0';
|
|
|
252 |
}
|
|
|
253 |
else {
|
|
|
254 |
$sessData['status']['type'] = 'error';
|
|
|
255 |
$sessData['status']['msg'] = 'Some problem occurred, please try again.';
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
else {
|
|
|
259 |
$sessData['status']['type'] = 'error';
|
|
|
260 |
$sessData['status']['msg'] = 'Given email is not associated with any account.';
|
|
|
261 |
}
|
36 |
- |
262 |
|
65 |
- |
263 |
}
|
|
|
264 |
else {
|
25 |
- |
265 |
$sessData['status']['type'] = 'error';
|
36 |
- |
266 |
$sessData['status']['msg'] = 'Enter email to create a new password for your account.';
|
25 |
- |
267 |
}
|
36 |
- |
268 |
|
65 |
- |
269 |
// Store reset password status into the session
|
25 |
- |
270 |
$_SESSION['sessData'] = $sessData;
|
36 |
- |
271 |
|
65 |
- |
272 |
// Redirect to the forgot pasword page
|
31 |
- |
273 |
MySessionHandler::commit(session_id());
|
65 |
- |
274 |
header("Location:forgotPassword.php" . $frmDisplay);
|
|
|
275 |
}
|
|
|
276 |
elseif (isset($_POST['resetSubmit'])) {
|
|
|
277 |
$fp_code = sanitizeInput($_POST['fp_code']);
|
36 |
- |
278 |
|
65 |
- |
279 |
// Get user inputs
|
|
|
280 |
$password = sanitizeInput($_POST['password']);
|
|
|
281 |
$confirm_password = sanitizeInput($_POST['confirm_password']);
|
36 |
- |
282 |
|
65 |
- |
283 |
if (!empty($password) && !empty($confirm_password) && !empty($fp_code)) {
|
|
|
284 |
// Password and confirm password comparison
|
|
|
285 |
if ($password !== $confirm_password) {
|
25 |
- |
286 |
$sessData['status']['type'] = 'error';
|
|
|
287 |
$sessData['status']['msg'] = 'Confirm password does not match the password.';
|
65 |
- |
288 |
}
|
|
|
289 |
else {
|
|
|
290 |
//check whether identity code exists in the database
|
|
|
291 |
$cond['where'] = array(
|
|
|
292 |
'forgot_pass_identity' => $fp_code
|
|
|
293 |
);
|
25 |
- |
294 |
$cond['return_type'] = 'count';
|
|
|
295 |
$userCount = $user->getRows($cond);
|
65 |
- |
296 |
if ($userCount > 0) {
|
|
|
297 |
// Update data with new password
|
|
|
298 |
$conditions = array(
|
|
|
299 |
'forgot_pass_identity' => $fp_code
|
|
|
300 |
);
|
|
|
301 |
$data = array(
|
|
|
302 |
'password' => password_hash($password, PASSWORD_DEFAULT)
|
|
|
303 |
);
|
|
|
304 |
$update = $user->update($data, $conditions);
|
|
|
305 |
if ($update) {
|
|
|
306 |
$sessData['status']['type'] = 'success';
|
43 |
- |
307 |
$sessData['status']['msg'] = 'Your account password has been reset. Please login with your new password.';
|
65 |
- |
308 |
}
|
|
|
309 |
else {
|
|
|
310 |
$sessData['status']['type'] = 'error';
|
|
|
311 |
$sessData['status']['msg'] = 'Some problem occurred, please try again.';
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
else {
|
25 |
- |
315 |
$sessData['status']['type'] = 'error';
|
|
|
316 |
$sessData['status']['msg'] = 'You are not authorized to reset the password for this account.';
|
|
|
317 |
}
|
|
|
318 |
}
|
65 |
- |
319 |
}
|
|
|
320 |
else {
|
25 |
- |
321 |
$sessData['status']['type'] = 'error';
|
36 |
- |
322 |
$sessData['status']['msg'] = 'All fields are mandatory, please fill all the fields.';
|
25 |
- |
323 |
}
|
36 |
- |
324 |
|
65 |
- |
325 |
// Store reset password status into the session
|
25 |
- |
326 |
$_SESSION['sessData'] = $sessData;
|
65 |
- |
327 |
$redirectURL = ($sessData['status']['type'] == 'success') ? 'index.php' : 'resetPassword.php?fp_code=' . $fp_code;
|
36 |
- |
328 |
|
65 |
- |
329 |
// Redirect to the login/reset pasword page
|
31 |
- |
330 |
MySessionHandler::commit(session_id());
|
65 |
- |
331 |
header("Location:" . $redirectURL);
|
|
|
332 |
exit;
|
|
|
333 |
}
|
|
|
334 |
elseif (isset($_REQUEST['verifyEmail']) && $_REQUEST['verifyEmail'] == 1) {
|
|
|
335 |
$ac_code = $_REQUEST['ac_code'];
|
25 |
- |
336 |
|
65 |
- |
337 |
// Check whether activation code exists in the database
|
|
|
338 |
$cond['where'] = array(
|
|
|
339 |
'activation_code' => $ac_code
|
|
|
340 |
);
|
|
|
341 |
$cond['return_type'] = 'count';
|
|
|
342 |
$userCount = $user->getRows($cond);
|
|
|
343 |
if ($userCount > 0) {
|
|
|
344 |
// Update data with new password
|
|
|
345 |
$conditions = array(
|
|
|
346 |
'activation_code' => $ac_code
|
|
|
347 |
);
|
|
|
348 |
$data = array(
|
|
|
349 |
'activated' => '1'
|
|
|
350 |
);
|
|
|
351 |
$update = $user->update($data, $conditions);
|
|
|
352 |
if ($update) {
|
|
|
353 |
$sessData['status']['type'] = 'success';
|
|
|
354 |
$sessData['status']['msg'] = 'Email verification for your account was successful. Please login to your account.';
|
|
|
355 |
}
|
|
|
356 |
else {
|
|
|
357 |
$sessData['status']['type'] = 'error';
|
|
|
358 |
$sessData['status']['msg'] = 'Some problem occurred, please try again.';
|
|
|
359 |
}
|
|
|
360 |
}
|
|
|
361 |
else {
|
|
|
362 |
$sessData['status']['type'] = 'error';
|
|
|
363 |
$sessData['status']['msg'] = 'You have used the wrong verification link, please check your email inbox and try again.';
|
|
|
364 |
}
|
36 |
- |
365 |
|
65 |
- |
366 |
// Store account activation status into the session
|
25 |
- |
367 |
$_SESSION['sessData'] = $sessData;
|
30 |
- |
368 |
$redirectURL = 'index.php';
|
36 |
- |
369 |
|
65 |
- |
370 |
// Redirect to the login page
|
31 |
- |
371 |
MySessionHandler::commit(session_id());
|
65 |
- |
372 |
header("Location:" . $redirectURL);
|
|
|
373 |
exit;
|
|
|
374 |
}
|
|
|
375 |
elseif (isset($_POST['updateProfile']) && !empty($_SESSION['sessData']['userID'])) {
|
|
|
376 |
$valErr = 0;
|
36 |
- |
377 |
|
65 |
- |
378 |
$sessData = $_SESSION['sessData'];
|
|
|
379 |
unset($sessData['field_error']);
|
|
|
380 |
unset($sessData['status']);
|
|
|
381 |
$sessUserId = $sessData['userID'];
|
36 |
- |
382 |
|
65 |
- |
383 |
//echo "<pre>", print_r($_POST, 1), "</pre>";
|
|
|
384 |
//exit;
|
|
|
385 |
// Get user inputs
|
|
|
386 |
$first_name = sanitizeInput($_POST['first_name']);
|
|
|
387 |
$last_name = sanitizeInput($_POST['last_name']);
|
|
|
388 |
$email = sanitizeInput($_POST['email']);
|
|
|
389 |
$zip = sanitizeInput($_POST['zip']);
|
|
|
390 |
$theme = strtolower(sanitizeInput($_POST['theme']));
|
59 |
- |
391 |
$cardView = $_POST['cardView'];
|
65 |
- |
392 |
$conditionNew = isset($_POST['filterConditionNew']) ? 1 : 0;
|
|
|
393 |
$conditionUsed = isset($_POST['filterConditionUsed']) ? 1 : 0;
|
|
|
394 |
$mediaCD = isset($_POST['filterMediaTypeCD']) ? 1 : 0;
|
|
|
395 |
$mediaRecord = isset($_POST['filterMediaTypeRecord']) ? 1 : 0;
|
|
|
396 |
$mediaDigital = isset($_POST['filterMediaTypeDigital']) ? 1 : 0;
|
|
|
397 |
$mediaBook = isset($_POST['filterMediaTypeBook']) ? 1 : 0;
|
71 |
- |
398 |
$wlEmail = $_POST['wlEmail'];
|
|
|
399 |
$wlFreq = $_POST['wlFreq'];
|
36 |
- |
400 |
|
65 |
- |
401 |
if (empty($first_name)) {
|
|
|
402 |
$valErr = 1;
|
|
|
403 |
$sessData['field_error']['first_name'] = 'Please enter your first name.';
|
|
|
404 |
}
|
|
|
405 |
/*
|
|
|
406 |
if(empty($last_name)){
|
|
|
407 |
$valErr = 1;
|
|
|
408 |
$sessData['field_error']['last_name'] = 'Please enter your last name.';
|
|
|
409 |
}
|
|
|
410 |
*/
|
|
|
411 |
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
|
412 |
$valErr = 1;
|
|
|
413 |
$sessData['field_error']['email'] = 'Please enter a valid email.';
|
|
|
414 |
}
|
25 |
- |
415 |
|
65 |
- |
416 |
if ($valErr == 0) {
|
|
|
417 |
// Check whether user exists in the database
|
|
|
418 |
$cond['where'] = array(
|
|
|
419 |
'email' => $email
|
|
|
420 |
);
|
|
|
421 |
$cond['where_not'] = array(
|
|
|
422 |
'id' => $sessUserId
|
|
|
423 |
);
|
|
|
424 |
$cond['return_type'] = 'count';
|
|
|
425 |
$userCount = $user->getRows($cond);
|
|
|
426 |
if ($userCount > 0) {
|
|
|
427 |
$sessData['status']['type'] = 'error';
|
|
|
428 |
$sessData['status']['msg'] = 'Email already exists, please use another email.';
|
|
|
429 |
}
|
|
|
430 |
else {
|
|
|
431 |
// Get user information
|
|
|
432 |
$conditions['where'] = array(
|
|
|
433 |
'id' => $sessData['userID'],
|
|
|
434 |
);
|
|
|
435 |
$conditions['return_type'] = 'single';
|
|
|
436 |
$userData = $user->getRows($conditions);
|
|
|
437 |
$prevPicture = $userData['picture'];
|
36 |
- |
438 |
|
65 |
- |
439 |
// Prepare user data
|
|
|
440 |
$userData = array(
|
|
|
441 |
'first_name' => $first_name,
|
|
|
442 |
'last_name' => $last_name,
|
|
|
443 |
'email' => $email,
|
|
|
444 |
'zip' => $zip,
|
|
|
445 |
'conditionNew' => $conditionNew,
|
|
|
446 |
'conditionUsed' => $conditionUsed,
|
|
|
447 |
'mediaCD' => $mediaCD,
|
|
|
448 |
'mediaRecord' => $mediaRecord,
|
|
|
449 |
'mediaDigital' => $mediaDigital,
|
|
|
450 |
'mediaBook' => $mediaBook,
|
59 |
- |
451 |
'theme' => $theme,
|
71 |
- |
452 |
'cardView' => $cardView,
|
|
|
453 |
'wlEmailFlag' => $wlEmail,
|
|
|
454 |
'wlFreq' => $wlFreq
|
65 |
- |
455 |
);
|
36 |
- |
456 |
|
65 |
- |
457 |
// Profile picture upload
|
|
|
458 |
$fileErr = 0;
|
|
|
459 |
if (!empty($_FILES['picture']['name'])) {
|
|
|
460 |
$targetDir = UPLOAD_PATH . 'profile_picture/';
|
|
|
461 |
$fileName = time() . '_' . basename($_FILES["picture"]["tmp_name"]);
|
|
|
462 |
$targetFilePath = $targetDir . $fileName;
|
|
|
463 |
$fileType = strtolower(pathinfo($_FILES["picture"]["name"], PATHINFO_EXTENSION));
|
|
|
464 |
$allowTypes = array(
|
|
|
465 |
'jpg',
|
|
|
466 |
'png',
|
|
|
467 |
'jpeg',
|
|
|
468 |
'gif'
|
|
|
469 |
);
|
|
|
470 |
if (in_array($fileType, $allowTypes)) {
|
36 |
- |
471 |
if ($_FILES["picture"]["size"] > 500000) {
|
65 |
- |
472 |
$fileErr = 1;
|
|
|
473 |
$sessData['status']['type'] = 'error';
|
|
|
474 |
$sessData['status']['msg'] = 'Please upload a smaller image file.';
|
|
|
475 |
}
|
|
|
476 |
else {
|
36 |
- |
477 |
$check = getimagesize($_FILES["picture"]["tmp_name"]);
|
|
|
478 |
if ($check === false) {
|
65 |
- |
479 |
$fileErr = 1;
|
|
|
480 |
$sessData['status']['type'] = 'error';
|
|
|
481 |
$sessData['status']['msg'] = 'Please upload only gif/jpg/png files.';
|
36 |
- |
482 |
}
|
|
|
483 |
}
|
|
|
484 |
}
|
65 |
- |
485 |
else {
|
|
|
486 |
$fileErr = 1;
|
|
|
487 |
$sessData['status']['type'] = 'error';
|
|
|
488 |
$sessData['status']['msg'] = 'Please upload only gif/jpg/png files.';
|
|
|
489 |
}
|
36 |
- |
490 |
|
65 |
- |
491 |
if ($fileErr == 0) {
|
|
|
492 |
if (move_uploaded_file($_FILES["picture"]["tmp_name"], $targetFilePath)) {
|
|
|
493 |
$userData['picture'] = $fileName;
|
36 |
- |
494 |
|
65 |
- |
495 |
// Delete previous profile picture
|
|
|
496 |
@unlink(UPLOAD_PATH . 'profile_picture/' . $prevPicture);
|
|
|
497 |
}
|
|
|
498 |
else {
|
36 |
- |
499 |
$fileErr = 1;
|
65 |
- |
500 |
$sessData['status']['type'] = 'error';
|
|
|
501 |
$sessData['status']['msg'] = 'Could not upload picture.';
|
|
|
502 |
@unlink($_FILES["picture"]["tmp_name"]);
|
|
|
503 |
}
|
|
|
504 |
}
|
|
|
505 |
else {
|
|
|
506 |
@unlink($_FILES["picture"]["tmp_name"]);
|
|
|
507 |
}
|
|
|
508 |
}
|
36 |
- |
509 |
|
65 |
- |
510 |
if ($fileErr == 0) {
|
|
|
511 |
// Update user data in the database
|
|
|
512 |
$conditions = array(
|
|
|
513 |
'id' => $sessUserId
|
|
|
514 |
);
|
36 |
- |
515 |
|
65 |
- |
516 |
$update = $user->update($userData, $conditions);
|
36 |
- |
517 |
|
65 |
- |
518 |
// Set status based on data insert
|
|
|
519 |
if ($update) {
|
|
|
520 |
$sessData['status']['type'] = 'success';
|
|
|
521 |
$sessData['status']['msg'] = 'Your profile information has been updated.';
|
|
|
522 |
}
|
|
|
523 |
else {
|
|
|
524 |
$sessData['status']['type'] = 'error';
|
|
|
525 |
$sessData['status']['msg'] = 'Some problem occurred, please try again.';
|
|
|
526 |
}
|
36 |
- |
527 |
}
|
65 |
- |
528 |
}
|
|
|
529 |
}
|
|
|
530 |
else {
|
25 |
- |
531 |
$sessData['status']['type'] = 'error';
|
36 |
- |
532 |
$sessData['status']['msg'] = 'Please fill all mandatory fields.';
|
25 |
- |
533 |
}
|
36 |
- |
534 |
|
65 |
- |
535 |
// Store signup status into the session
|
25 |
- |
536 |
$_SESSION['sessData'] = $sessData;
|
65 |
- |
537 |
$redirectURL = 'editAccount.php';
|
36 |
- |
538 |
|
65 |
- |
539 |
// Redirect to the profile page
|
31 |
- |
540 |
MySessionHandler::commit(session_id());
|
65 |
- |
541 |
header("Location:" . $redirectURL);
|
|
|
542 |
exit;
|
|
|
543 |
}
|
|
|
544 |
elseif (isset($_POST['updatePassword']) && !empty($_SESSION['sessData']['userID'])) {
|
|
|
545 |
$sessData = $_SESSION['sessData'];
|
|
|
546 |
unset($sessData['field_error']);
|
|
|
547 |
unset($sessData['status']);
|
|
|
548 |
$sessUserId = $sessData['userID'];
|
36 |
- |
549 |
|
65 |
- |
550 |
// Get user inputs
|
|
|
551 |
$old_password = sanitizeInput($_POST['old_password']);
|
|
|
552 |
$password = sanitizeInput($_POST['password']);
|
|
|
553 |
$confirm_password = sanitizeInput($_POST['confirm_password']);
|
36 |
- |
554 |
|
65 |
- |
555 |
if (!empty($password) && !empty($confirm_password)) {
|
|
|
556 |
// Password and confirm password comparison
|
|
|
557 |
if ($password !== $confirm_password) {
|
25 |
- |
558 |
$sessData['status']['type'] = 'error';
|
|
|
559 |
$sessData['status']['msg'] = 'Confirm password does not match the password.';
|
65 |
- |
560 |
}
|
|
|
561 |
else {
|
|
|
562 |
// Check whether identity code exists in the database
|
|
|
563 |
$cond['where'] = array(
|
|
|
564 |
'id' => $sessUserId
|
|
|
565 |
);
|
25 |
- |
566 |
$cond['return_type'] = 'single';
|
|
|
567 |
$userData = $user->getRows($cond);
|
36 |
- |
568 |
|
65 |
- |
569 |
if ((!empty($userData) && !empty($sessData['loginType']) && $sessData['loginType'] == 'social') || (!empty($userData) && password_verify($old_password, $userData['password']))) {
|
|
|
570 |
// Update data with new password
|
|
|
571 |
$conditions = array(
|
|
|
572 |
'id' => $sessUserId
|
|
|
573 |
);
|
|
|
574 |
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
|
|
|
575 |
$data = array(
|
|
|
576 |
'password' => $passwordHash
|
|
|
577 |
);
|
|
|
578 |
$update = $user->update($data, $conditions);
|
|
|
579 |
if ($update) {
|
|
|
580 |
if (!empty($_COOKIE['rememberUserId'])) {
|
|
|
581 |
setcookie('hash', password_hash($passwordHash . $sessUserId, PASSWORD_DEFAULT) , time() + (30 * 86400) , "/");
|
|
|
582 |
}
|
|
|
583 |
$sessData['status']['type'] = 'success';
|
43 |
- |
584 |
$sessData['status']['msg'] = 'Your account password has been updated.';
|
65 |
- |
585 |
}
|
|
|
586 |
else {
|
|
|
587 |
$sessData['status']['type'] = 'error';
|
|
|
588 |
$sessData['status']['msg'] = 'Some problem occurred, please try again.';
|
|
|
589 |
}
|
|
|
590 |
}
|
|
|
591 |
else {
|
25 |
- |
592 |
$sessData['status']['type'] = 'error';
|
|
|
593 |
$sessData['status']['msg'] = 'The given old password does not match your current account password.';
|
|
|
594 |
}
|
|
|
595 |
}
|
65 |
- |
596 |
}
|
|
|
597 |
else {
|
25 |
- |
598 |
$sessData['status']['type'] = 'error';
|
36 |
- |
599 |
$sessData['status']['msg'] = 'Please fill all mandatory fields.';
|
25 |
- |
600 |
}
|
36 |
- |
601 |
|
65 |
- |
602 |
// Store reset password status into the session
|
25 |
- |
603 |
$_SESSION['sessData'] = $sessData;
|
26 |
- |
604 |
$redirectURL = 'changePassword.php';
|
36 |
- |
605 |
|
65 |
- |
606 |
// Redirect to the pasword settings page
|
31 |
- |
607 |
MySessionHandler::commit(session_id());
|
65 |
- |
608 |
header("Location:" . $redirectURL);
|
|
|
609 |
exit;
|
|
|
610 |
}
|
|
|
611 |
elseif (!empty($_REQUEST['logoutSubmit'])) {
|
|
|
612 |
// Include social login handler
|
|
|
613 |
if (!empty($_SESSION['sessData']['loginType']) && ($_SESSION['sessData']['loginType'] == 'social') && !empty($_SESSION['google_access_token'])) {
|
|
|
614 |
require_once 'includes/socialLogin.php';
|
|
|
615 |
}
|
36 |
- |
616 |
|
65 |
- |
617 |
// Remove cookie data
|
|
|
618 |
setcookie("rememberUserId", "", time() - 3600, "/");
|
|
|
619 |
setcookie("hash", "", time() - 3600, "/");
|
31 |
- |
620 |
unset($_COOKIE['rememberUserId']);
|
|
|
621 |
unset($_COOKIE['hash']);
|
36 |
- |
622 |
|
65 |
- |
623 |
// Remove session data
|
|
|
624 |
unset($_SESSION['facebook_access_token']);
|
|
|
625 |
unset($_SESSION['FBRLH_state']);
|
|
|
626 |
if (isset($_SESSION['google_access_token'])) {
|
|
|
627 |
// Reset OAuth access token
|
|
|
628 |
$gClient->revokeToken();
|
|
|
629 |
}
|
|
|
630 |
unset($_SESSION['google_access_token']);
|
|
|
631 |
unset($_SESSION['twitter_access_token']);
|
|
|
632 |
unset($_SESSION['twitter_token_secret']);
|
25 |
- |
633 |
unset($_SESSION['sessData']);
|
|
|
634 |
session_destroy();
|
36 |
- |
635 |
|
65 |
- |
636 |
// Store logout status into the session
|
25 |
- |
637 |
$sessData['status']['type'] = 'success';
|
|
|
638 |
$sessData['status']['msg'] = 'You have logged off your account.';
|
|
|
639 |
$_SESSION['sessData'] = $sessData;
|
36 |
- |
640 |
|
65 |
- |
641 |
// Redirect to the home page
|
31 |
- |
642 |
MySessionHandler::commit(session_id());
|
|
|
643 |
header("Location:../index.php");
|
65 |
- |
644 |
exit;
|
|
|
645 |
}
|
|
|
646 |
else {
|
|
|
647 |
// Redirect to the home page
|
31 |
- |
648 |
MySessionHandler::commit(session_id());
|
|
|
649 |
header("Location:../index.php");
|
65 |
- |
650 |
exit;
|
25 |
- |
651 |
}
|
36 |
- |
652 |
|
|
|
653 |
// sanitize user input
|
|
|
654 |
function sanitizeInput($data) {
|
|
|
655 |
$data = trim(preg_replace('/[\t\n\r\s]+/', ' ', $data));
|
|
|
656 |
$data = stripslashes($data);
|
|
|
657 |
$data = htmlspecialchars($data);
|
|
|
658 |
return $data;
|
|
|
659 |
}
|