Beispiel #1
0
 protected function _getWrapper($selected, XenForo_ControllerResponse_View $subView)
 {
     $viewParams = array('selected' => $selected, 'tosUrl' => XenForo_Dependencies_Public::getTosUrl());
     $wrapper = $this->responseView('XenForo_ViewPublic_Help_Wrapper', 'help_wrapper', $viewParams);
     $wrapper->subView = $subView;
     return $wrapper;
 }
Beispiel #2
0
 /**
  * Confirm agreement to revised set of terms and conditions on the site.
  */
 public function actionTerms()
 {
     $agree = $this->_input->filterSingle('agree', XenForo_Input::UINT);
     if ($this->isConfirmedPost() && $agree) {
         $userId = XenForo_Visitor::getUserId();
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
         $dw->setExistingData($userId);
         $dw->set('agree_terms_th', 0);
         $dw->save();
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(false, true));
     }
     $viewParams = array('agree_to_terms' => true, 'tosUrl' => XenForo_Dependencies_Public::getTosUrl());
     return $this->_getWrapper('account', 'terms', $this->responseView('XenForo_ViewPublic_Account_Terms', 'th_account_terms_agreetermsofserv', $viewParams));
 }
Beispiel #3
0
 protected function _setupExternalUser(array $data)
 {
     $this->_assertRegistrationActive();
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         throw $this->responseException($this->responseError(new XenForo_Phrase('you_must_agree_to_terms_of_service')));
     }
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $options = XenForo_Application::get('options');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     $writer->bulkSet($data);
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $customFields = $this->_input->filterSingle('custom_fields', XenForo_Input::ARRAY_SIMPLE);
     $customFieldsShown = array_keys($this->_getFieldModel()->getUserFields(array('registration' => true)));
     $writer->setCustomFields($customFields, $customFieldsShown);
     $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
     $writer->set('scheme_class', $auth->getClassName());
     $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
     return $writer;
 }
Beispiel #4
0
 protected function _getWrapper($selected, XenForo_ControllerResponse_View $subView)
 {
     if ($this->_pagesCache !== null) {
         $pages = $this->_pagesCache;
     } else {
         $helpModel = $this->_getHelpModel();
         $pages = $helpModel->preparePages($helpModel->getHelpPages());
     }
     $viewParams = array('selected' => $selected, 'tosUrl' => XenForo_Dependencies_Public::getTosUrl(), 'pages' => $pages);
     $wrapper = $this->responseView('XenForo_ViewPublic_Help_Wrapper', 'help_wrapper', $viewParams);
     $wrapper->subView = $subView;
     return $wrapper;
 }
Beispiel #5
0
 /**
  * Registers a new account (or associates with an existing one) using Facebook.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionFacebookRegister()
 {
     $this->_assertPostOnly();
     $fbToken = $this->_input->filterSingle('fb_token', XenForo_Input::STRING);
     $fbUser = XenForo_Helper_Facebook::getUserInfo($fbToken);
     if (empty($fbUser['id'])) {
         return $this->responseError(new XenForo_Phrase('error_occurred_while_connecting_with_facebook'));
     }
     $userModel = $this->_getUserModel();
     $userExternalModel = $this->_getUserExternalModel();
     $doAssoc = $this->_input->filterSingle('associate', XenForo_Input::STRING) || $this->_input->filterSingle('force_assoc', XenForo_Input::UINT);
     if ($doAssoc) {
         $associate = $this->_input->filter(array('associate_login' => XenForo_Input::STRING, 'associate_password' => XenForo_Input::STRING));
         $loginModel = $this->_getLoginModel();
         if ($loginModel->requireLoginCaptcha($associate['associate_login'])) {
             return $this->responseError(new XenForo_Phrase('your_account_has_temporarily_been_locked_due_to_failed_login_attempts'));
         }
         $userId = $userModel->validateAuthentication($associate['associate_login'], $associate['associate_password'], $error);
         if (!$userId) {
             $loginModel->logLoginAttempt($associate['associate_login']);
             return $this->responseError($error);
         }
         $userExternalModel->updateExternalAuthAssociation('facebook', $fbUser['id'], $userId);
         XenForo_Helper_Facebook::setUidCookie($fbUser['id']);
         XenForo_Application::get('session')->changeUserId($userId);
         XenForo_Visitor::setup($userId);
         $redirect = XenForo_Application::get('session')->get('fbRedirect');
         XenForo_Application::get('session')->remove('fbRedirect');
         if (!$redirect) {
             $redirect = $this->getDynamicRedirect(false, false);
         }
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $redirect);
     }
     $this->_assertRegistrationActive();
     $data = $this->_input->filter(array('username' => XenForo_Input::STRING, 'timezone' => XenForo_Input::STRING));
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         return $this->responseError(new XenForo_Phrase('you_must_agree_to_terms_of_service'));
     }
     $options = XenForo_Application::get('options');
     $gender = '';
     if (isset($fbUser['gender'])) {
         switch ($fbUser['gender']) {
             case 'man':
             case 'male':
                 $gender = 'male';
                 break;
             case 'woman':
             case 'female':
                 $gender = 'female';
                 break;
         }
     }
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     $writer->bulkSet($data);
     $writer->bulkSet(array('gender' => $gender, 'email' => $fbUser['email'], 'location' => isset($fbUser['location']['name']) ? $fbUser['location']['name'] : ''));
     if (!empty($fbUser['birthday'])) {
         $birthdayParts = explode('/', $fbUser['birthday']);
         if (count($birthdayParts) == 3) {
             list($month, $day, $year) = $birthdayParts;
             $userAge = $this->_getUserProfileModel()->calculateAge($year, $month, $day);
             if ($userAge < intval($options->get('registrationSetup', 'minimumAge'))) {
                 // TODO: set a cookie to prevent re-registration attempts
                 return $this->responseError(new XenForo_Phrase('sorry_you_too_young_to_create_an_account'));
             }
             $writer->bulkSet(array('dob_year' => $year, 'dob_month' => $month, 'dob_day' => $day));
         }
     }
     if (!empty($fbUser['website'])) {
         list($website) = preg_split('/\\r?\\n/', $fbUser['website']);
         if ($website && Zend_Uri::check($website)) {
             $writer->set('homepage', $website);
         }
     }
     $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
     $writer->set('scheme_class', $auth->getClassName());
     $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $writer->advanceRegistrationUserState(false);
     $writer->preSave();
     // TODO: option for extra user group
     $writer->save();
     $user = $writer->getMergedData();
     $avatarFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
     if ($avatarFile) {
         $data = XenForo_Helper_Facebook::getUserPicture($fbToken);
         if ($data && $data[0] != '{') {
             file_put_contents($avatarFile, $data);
             try {
                 $user = array_merge($user, $this->getModelFromCache('XenForo_Model_Avatar')->applyAvatar($user['user_id'], $avatarFile));
             } catch (XenForo_Exception $e) {
             }
         }
         @unlink($avatarFile);
     }
     $userExternalModel->updateExternalAuthAssociation('facebook', $fbUser['id'], $user['user_id']);
     XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register');
     XenForo_Helper_Facebook::setUidCookie($fbUser['id']);
     XenForo_Application::get('session')->changeUserId($user['user_id']);
     XenForo_Visitor::setup($user['user_id']);
     $redirect = $this->_input->filterSingle('redirect', XenForo_Input::STRING);
     $viewParams = array('user' => $user, 'redirect' => $redirect ? XenForo_Link::convertUriToAbsoluteUri($redirect) : '', 'facebook' => true);
     return $this->responseView('XenForo_ViewPublic_Register_Process', 'register_process', $viewParams, $this->_getRegistrationContainerParams());
 }
Beispiel #6
0
 public function actionExternalRegister()
 {
     $this->_assertPostOnly();
     $redirect = $this->_bdApiConsumer_getRedirect();
     $userModel = $this->_getUserModel();
     /** @var bdApiConsumer_XenForo_Model_UserExternal $userExternalModel */
     $userExternalModel = $this->_getUserExternalModel();
     $providerCode = $this->_input->filterSingle('provider', XenForo_Input::STRING);
     $provider = bdApiConsumer_Option::getProviderByCode($providerCode);
     if (empty($provider)) {
         return $this->responseNoPermission();
     }
     $doAssoc = $this->_input->filterSingle('associate', XenForo_Input::STRING) || $this->_input->filterSingle('force_assoc', XenForo_Input::UINT);
     $userId = 0;
     if ($doAssoc) {
         $associate = $this->_input->filter(array('associate_login' => XenForo_Input::STRING, 'associate_password' => XenForo_Input::STRING));
         $loginModel = $this->_getLoginModel();
         if ($loginModel->requireLoginCaptcha($associate['associate_login'])) {
             return $this->responseError(new XenForo_Phrase('your_account_has_temporarily_been_locked_due_to_failed_login_attempts'));
         }
         $userId = $userModel->validateAuthentication($associate['associate_login'], $associate['associate_password'], $error);
         if (!$userId) {
             $loginModel->logLoginAttempt($associate['associate_login']);
             return $this->responseError($error);
         }
     }
     $refreshToken = $this->_input->filterSingle('refresh_token', XenForo_Input::STRING);
     $externalToken = bdApiConsumer_Helper_Api::getAccessTokenFromRefreshToken($provider, $refreshToken);
     if (empty($externalToken)) {
         return $this->responseError(new XenForo_Phrase('bdapi_consumer_error_occurred_while_connecting_with_x', array('provider' => $provider['name'])));
     }
     $externalVisitor = bdApiConsumer_Helper_Api::getVisitor($provider, $externalToken['access_token']);
     if (empty($externalVisitor)) {
         return $this->responseError(new XenForo_Phrase('bdapi_consumer_error_occurred_while_connecting_with_x', array('provider' => $provider['name'])));
     }
     if (empty($externalVisitor['user_email'])) {
         return $this->responseError(new XenForo_Phrase('bdapi_consumer_x_returned_unknown_error', array('provider' => $provider['name'])));
     }
     if (isset($externalVisitor['user_is_valid']) and isset($externalVisitor['user_is_verified'])) {
         if (empty($externalVisitor['user_is_valid']) or empty($externalVisitor['user_is_verified'])) {
             return $this->responseError(new XenForo_Phrase('bdapi_consumer_x_account_not_good_standing', array('provider' => $provider['name'])));
         }
     }
     if ($doAssoc) {
         $userExternalModel->bdApiConsumer_updateExternalAuthAssociation($provider, $externalVisitor['user_id'], $userId, array_merge($externalVisitor, array('token' => $externalToken)));
         XenForo_Application::getSession()->changeUserId($userId);
         XenForo_Visitor::setup($userId);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $redirect);
     }
     if (bdApiConsumer_Option::get('bypassRegistrationActive')) {
         // do not check for registration active option
     } else {
         $this->_assertRegistrationActive();
     }
     $data = $this->_input->filter(array('username' => XenForo_Input::STRING, 'timezone' => XenForo_Input::STRING));
     // TODO: custom fields
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         return $this->responseError(new XenForo_Phrase('you_must_agree_to_terms_of_service'));
     }
     $user = bdApiConsumer_Helper_AutoRegister::createUser($data, $provider, $externalToken, $externalVisitor, $this->_getUserExternalModel());
     XenForo_Application::getSession()->changeUserId($user['user_id']);
     XenForo_Visitor::setup($user['user_id']);
     $viewParams = array('user' => $user, 'redirect' => $redirect);
     return $this->responseView('XenForo_ViewPublic_Register_Process', 'register_process', $viewParams, $this->_getRegistrationContainerParams());
 }
 public function actionSteamRegister()
 {
     $this->_assertPostOnly();
     $session = XenForo_Application::get('session');
     if (!$session->get('steam_id')) {
         return $this->responseError('Lost Steam ID');
     }
     // Get User Profile Data
     $id = $session->get('steam_id');
     $sHelper = new Steam_Helper_Steam();
     $steamProfileAPI = $sHelper->getSteamProfileAPI($id);
     $json_object = $sHelper->getJsonData($steamProfileAPI);
     $json_decoded = json_decode($json_object);
     if (!empty($json_decoded)) {
         $username = $json_decoded->response->players[0]->personaname;
         $avatar = $json_decoded->response->players[0]->avatarfull;
     }
     $userModel = $this->_getUserModel();
     $userExternalModel = $this->_getUserExternalModel();
     $doAssoc = $this->_input->filterSingle('associate', XenForo_Input::STRING) || $this->_input->filterSingle('force_assoc', XenForo_Input::UINT);
     if ($doAssoc) {
         $userId = $this->_associateExternalAccount();
         $userExternalModel->updateExternalAuthAssociation('steam', $id, $userId);
         $this->updateUserStats($userId, $id);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(false, false));
     }
     $data = $this->_input->filter(array('username' => XenForo_Input::STRING, 'timezone' => XenForo_Input::STRING, 'email' => XenForo_Input::STRING, 'gender' => XenForo_Input::STRING, 'location' => XenForo_Input::STRING, 'dob_day' => XenForo_Input::UINT, 'dob_month' => XenForo_Input::UINT, 'dob_year' => XenForo_Input::UINT));
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         return $this->responseError(new XenForo_Phrase('you_must_agree_to_terms_of_service'));
     }
     $options = XenForo_Application::get('options');
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     $writer->bulkSet($data);
     $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
     $writer->set('scheme_class', $auth->getClassName());
     $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $customFields = $this->_input->filterSingle('custom_fields', XenForo_Input::ARRAY_SIMPLE);
     $customFieldsShown = $this->_input->filterSingle('custom_fields_shown', XenForo_Input::STRING, array('array' => true));
     $writer->setCustomFields($customFields, $customFieldsShown);
     $writer->advanceRegistrationUserState(false);
     $writer->preSave();
     if ($options->get('registrationSetup', 'requireDob')) {
         // dob required
         if (!$data['dob_day'] || !$data['dob_month'] || !$data['dob_year']) {
             $writer->error(new XenForo_Phrase('please_enter_valid_date_of_birth'), 'dob');
         } else {
             $userAge = $this->_getUserProfileModel()->getUserAge($writer->getMergedData(), true);
             if ($userAge < 1) {
             } else {
                 if ($userAge < intval($options->get('registrationSetup', 'minimumAge'))) {
                     // TODO: set a cookie to prevent re-registration attempts
                     // But I don't care
                     $writer->error(new XenForo_Phrase('sorry_you_too_young_to_create_an_account'));
                 }
             }
         }
     }
     $writer->save();
     $user = $writer->getMergedData();
     if (!$options->steamAvatarReg) {
         unset($avatar);
     }
     if (!empty($avatar)) {
         $avatarFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
         $httpClient = XenForo_Helper_Http::getClient(preg_replace('/\\s+/', '%20', $avatar));
         $response = $httpClient->request('GET');
         if ($response->isSuccessful()) {
             file_put_contents($avatarFile, $response->getBody());
         }
         // Apply Avatar
         try {
             $user = array_merge($user, $this->getModelFromCache('XenForo_Model_Avatar')->applyAvatar($user['user_id'], $avatarFile));
         } catch (XenForo_Exception $e) {
         }
         @unlink($avatarFile);
     }
     $userExternalModel->updateExternalAuthAssociation('steam', $id, $user['user_id']);
     XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register');
     /* Cookies */
     $userModel->setUserRememberCookie($user['user_id']);
     $session->changeUserId($user['user_id']);
     XenForo_Visitor::setup($user['user_id']);
     $this->updateUserStats($user['user_id'], $id);
     $redirect = $this->_input->filterSingle('redirect', XenForo_Input::STRING);
     $viewParams = array('user' => $user, 'redirect' => $redirect ? XenForo_Link::convertUriToAbsoluteUri($redirect) : '', 'steam' => true);
     return $this->responseView('XenForo_ViewPublic_Register_Process', 'register_process', $viewParams, $this->_getRegistrationContainerParams());
 }