public function __construct($userFields) { //check if supplied/empty foreach ($userFields as $field => $value) { if (!isSupplied($value)) { $array['err'] = true; $array['message'] = 'Please fill in ' . $field . '!'; echo json_encode($array); exit; } } //assign our variables $this->username = $userFields['Username']; $this->name = $userFields['Full Name']; $this->email = $userFields['Email']; $this->password = $userFields['Password']; $this->rPassword = $userFields['Repeat Password']; $this->country = $userFields['Country']; $this->dob = $userFields['Date of Birth']; $this->sex = $userFields['Gender']; //validate username /*(allow only alphanumeric,hyphen and underscores) */ if (preg_match('/[^a-z_\\-0-9]/i', $this->username)) { $array['err'] = true; $array['message'] = 'Username cannot have any space. It MUST be one word with 8 or more characters.'; echo json_encode($array); exit; } if (strlen($this->username) < 6) { $array['err'] = true; $array['message'] = 'Username MUST be 6 or more characters.'; echo json_encode($array); exit; } //check if the username is already taken if ($this->isRegistered($this->username, 'username')) { $array['err'] = true; $array['message'] = '' . $this->username . ' is taken. Please try another.'; echo json_encode($array); exit; } //validate email if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) { $array['err'] = true; $array['message'] = 'Your email is invalid.'; echo json_encode($array); exit; } //check if a user with the same email exists if ($this->isRegistered($this->email, 'email')) { $array['err'] = true; $array['message'] = 'A user with this email is already registered.'; echo json_encode($array); exit; } //check if passwords is long enough if (strlen($this->password) < 8) { $array['err'] = true; $array['message'] = 'Password MUST be 8 or more characters.'; echo json_encode($array); exit; } //check if the two passwords match if ($this->password !== $this->rPassword) { $array['err'] = true; $array['message'] = 'Password and Re-enter Password do not match.'; echo json_encode($array); exit; } //validate date format $format = "d/m/Y"; $this->dob = $this->validateDate($this->dob, $format); //hash the password $hashedPWD = password_hash($this->password, PASSWORD_DEFAULT); //save in a database global $isv_db; $stmt = $isv_db->prepare("INSERT INTO users (username,email,pwd,reg_date,last_activity) VALUES (?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP())"); $stmt->bind_param('sss', $this->username, $this->email, $hashedPWD); $stmt->execute(); //retrieve new user id $stmt->prepare("SELECT id FROM users WHERE email=?"); $stmt->bind_param('s', $this->email); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($userID); $stmt->fetch(); //save other details in user_profile table $stmt->prepare("INSERT INTO user_profile (user_id,fullname,gender,dob,country) VALUES (?,?,?,?,?)"); $stmt->bind_param('issss', $userID, $this->name, $this->sex, $this->dob, $this->country); $stmt->execute(); $stmt->close(); //send activation email if this is enabled $siteInfo = new siteManager(); $isv_siteSettings = $siteInfo->getSiteSettings(); $isv_siteDetails = $siteInfo->getSiteInfo(); if ($isv_siteSettings['user_validate'] === 1) { /* generate our validation code */ $validCode = $this->getValidationCode($hashedPWD); /* include our email functions file */ require_once ISVIPI_FUNCTIONS_BASE . 'emails/reg_emails.php'; /*send the email */ sendValidationEmail($this->email, $this->name, $validCode, $isv_siteDetails['s_email'], $isv_siteDetails['s_title'], $isv_siteDetails['s_url'], $isv_siteSettings['logo']); $msg = 'Account created. We have sent an email with an activation code to ' . $this->email . '. Follow instructions in the email to activate your account.'; } else { $msg = 'Account created. You can now login.'; } //notify admin if this is enabled if ($isv_siteSettings['notifyAdmin_newUser'] === 1) { notifyAdmin($this->name, 'New User', $isv_siteDetails['s_email'], $isv_siteDetails['s_title']); } //return success notice $array['err'] = false; $array['message'] = $msg; echo json_encode($array); exit; }
if ($pwd['New Password'] !== $pwd['Repeat New Password']) { $_SESSION['isv_error'] = 'New Password and Repeat New Password do not match.'; header('location:' . $from_url . ''); exit; } //change $change_pwd = new member($_SESSION['isv_user_id']); $change_pwd->change_pwd($pwd); } /*** PRIVACY SETTINGS **/ if ($operation === 'privacy') { //capture fields $privacySett = array('Feeds' => cleanPOST('feeds_privacy'), 'Phone' => cleanPOST('phone_privacy')); //check if any has not been supplied foreach ($privacySett as $field => $value) { if (!isSupplied($value)) { $_SESSION['isv_error'] = 'Please select a privacy setting for ' . $field . ' field.'; header('location:' . $from_url . ''); exit; } } //check if they were not altered if ($privacySett['Feeds'] !== "nobody" && $privacySett['Feeds'] !== "friends only" && $privacySett['Feeds'] !== "everyone") { $_SESSION['isv_error'] = 'An error occured. It appears some values may have been changed illegally.'; header('location:' . $from_url . ''); exit; } if ($privacySett['Phone'] !== "nobody" && $privacySett['Phone'] !== "friends only" && $privacySett['Phone'] !== "everyone") { $_SESSION['isv_error'] = 'An error occured. It appears some values may have been changed illegally.'; header('location:' . $from_url . ''); exit;