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