/** Responds to a request to create a new user. * **/ public function actionRegistration() { //We need at least a username, email, and password. if (empty($_REQUEST['username']) or empty($_REQUEST['password']) or empty($_REQUEST['email'])) { $this->sendAsJson(array('error' => 'insufficient data')); return; } $username = trim($_REQUEST['username']); $password = trim($_REQUEST['password']); $postdata = array('username' => $username, 'email' => $_REQUEST['email']); if (isset($_REQUEST['month']) and isset($_REQUEST['day']) and !empty($_REQUEST['year'])) { $postdata['birthday'] = $_REQUEST['year'] . '-' . str_pad($_REQUEST['month'], 2, '0', STR_PAD_LEFT) . '-' . str_pad($_REQUEST['day'], 2, '0', STR_PAD_LEFT); } if (!empty($_REQUEST['guardian'])) { $postdata['parentemail'] = $_REQUEST['guardian']; } $vboptions = vB5_Template_Options::instance()->getOptions(); $vboptions = $vboptions['options']; // Coppa cookie check $coppaage = vB5_Cookie::get('coppaage', vB5_Cookie::TYPE_STRING); if ($vboptions['usecoppa'] and $vboptions['checkcoppa']) { if ($coppaage) { $dob = explode('-', $coppaage); $month = $dob[0]; $day = $dob[1]; $year = $dob[2]; $postdata['birthday'] = $year . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-' . str_pad($day, 2, '0', STR_PAD_LEFT); } else { vB5_Cookie::set('coppaage', $_REQUEST['month'] . '-' . $_REQUEST['day'] . '-' . $_REQUEST['year'], 365, 0); } } // Fill in ReCaptcha data $recaptchaData = array(); if (!empty($_REQUEST['recaptcha_challenge_field'])) { $recaptchaData['recaptcha_challenge_field'] = $_REQUEST['recaptcha_challenge_field']; } if (!empty($_REQUEST['recaptcha_response_field'])) { $recaptchaData['recaptcha_response_field'] = $_REQUEST['recaptcha_response_field']; } if (!empty($recaptchaData)) { $_REQUEST['humanverify'] = $recaptchaData + (isset($_REQUEST['humanverify']) ? (array) $_REQUEST['humanverify'] : array()); } $api = Api_InterfaceAbstract::instance(); $data = array('userid' => 0, 'password' => $password, 'user' => $postdata, array(), array(), 'userfield' => !empty($_REQUEST['userfield']) ? $_REQUEST['userfield'] : false, array(), isset($_REQUEST['humanverify']) ? $_REQUEST['humanverify'] : '', array('registration' => true)); // add facebook data if ($api->callApi('facebook', 'isFacebookEnabled') && $api->callApi('facebook', 'userIsLoggedIn')) { $fbUserInfo = $api->callApi('facebook', 'getFbUserInfo'); $data['user']['fbuserid'] = $fbUserInfo['id']; $data['user']['fbname'] = $fbUserInfo['name']; $data['user']['timezoneoffset'] = $fbUserInfo['timezone']; $data['user']['fbjoindate'] = time(); $fb_profilefield_info = $this->getFacebookProfileinfo($fbUserInfo); if (!empty($fb_profilefield_info['birthday']) and empty($data['user']['birthday'])) { $data['user']['birthday'] = $fb_profilefield_info['birthday']; } if (empty($data['userfield'])) { $data['userfield'] = array(); } if ($vboptions['fb_userfield_biography']) { $data['userfield'] += array($vboptions['fb_userfield_biography'] => $fb_profilefield_info['biography']); } if ($vboptions['fb_userfield_location']) { $data['userfield'] += array($vboptions['fb_userfield_location'] => $fb_profilefield_info['location']); } if ($vboptions['fb_userfield_occupation']) { $data['userfield'] += array($vboptions['fb_userfield_occupation'] => $fb_profilefield_info['occupation']); } } // save data $response = $api->callApi('user', 'save', $data); if (!empty($response) and (!is_array($response) or !isset($response['errors']))) { // try to login $loginInfo = $api->callApi('user', 'login', array($username, $password, '', '', '')); if (!isset($loginInfo['errors']) or empty($loginInfo['errors'])) { // browser session expiration vB5_Cookie::set('sessionhash', $loginInfo['sessionhash'], 0, true); vB5_Cookie::set('password', $loginInfo['password'], 0); vB5_Cookie::set('userid', $loginInfo['userid'], 0); $urlPath = ''; if (!empty($_POST['urlpath'])) { $urlPath = base64_decode(trim($_POST['urlpath']), true); } if (!$urlPath or strpos($urlPath, '/auth/') !== false or strpos($urlPath, '/register') !== false or !vB5_Template_Runtime::allowRedirectToUrl($urlPath)) { $urlPath = vB5_Template_Options::instance()->get('options.frontendurl'); } $response = array('urlPath' => $urlPath); } else { if (!empty($loginInfo['errors'])) { $response = array('errors' => $loginInfo['errors']); } } if ($api->callApi('user', 'usecoppa')) { $response['usecoppa'] = true; $response['urlPath'] = vB5_Route::buildUrl('coppa-form|bburl'); } else { if ($vboptions['verifyemail']) { $response['msg'] = 'registeremail'; $response['msg_params'] = array(vB5_String::htmlSpecialCharsUni($postdata['username']), $postdata['email'], vB5_Template_Options::instance()->get('options.frontendurl')); } else { if ($vboptions['moderatenewmembers']) { $response['msg'] = 'moderateuser'; $response['msg_params'] = array(vB5_String::htmlSpecialCharsUni($postdata['username']), vB5_Template_Options::instance()->get('options.frontendurl')); } else { $frontendurl = vB5_Template_Options::instance()->get('options.frontendurl'); $routeProfile = $api->callApi('route', 'getUrl', array('route' => 'profile', 'data' => array('userid' => $loginInfo['userid']), array())); $routeuserSettings = $api->callApi('route', 'getUrl', array('route' => 'settings', 'data' => array('tab' => 'profile'), array())); $routeAccount = $api->callApi('route', 'getUrl', array('route' => 'settings', 'data' => array('tab' => 'account'), array())); $response['msg'] = 'registration_complete'; $response['msg_params'] = array(vB5_String::htmlSpecialCharsUni($postdata['username']), $frontendurl . $routeProfile, $frontendurl . $routeAccount, $frontendurl . $routeuserSettings, $frontendurl); } } } } $this->sendAsJson(array('response' => $response)); }