Example #1
0
 public static function createUser(array $data, array $provider, array $externalToken, array $externalVisitor, XenForo_Model_UserExternal $userExternalModel)
 {
     $user = null;
     /** @var bdApiConsumer_XenForo_Model_UserExternal $userExternalModel */
     $options = XenForo_Application::get('options');
     /** @var XenForo_DataWriter_User $writer */
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     if (!isset($data['timezone']) and isset($externalVisitor['user_timezone_offset'])) {
         $tzOffset = $externalVisitor['user_timezone_offset'];
         $tzName = timezone_name_from_abbr('', $tzOffset, 1);
         if ($tzName !== false) {
             $data['timezone'] = $tzName;
         }
     }
     if (!empty($data['user_id'])) {
         $writer->setImportMode(true);
     }
     $writer->bulkSet($data);
     if (!empty($data['user_id'])) {
         $writer->setImportMode(false);
     }
     $writer->set('email', $externalVisitor['user_email']);
     if (!empty($externalVisitor['user_gender'])) {
         $writer->set('gender', $externalVisitor['user_gender']);
     }
     if (!empty($externalVisitor['user_dob_day']) && !empty($externalVisitor['user_dob_month']) && !empty($externalVisitor['user_dob_year'])) {
         $writer->set('dob_day', $externalVisitor['user_dob_day']);
         $writer->set('dob_month', $externalVisitor['user_dob_month']);
         $writer->set('dob_year', $externalVisitor['user_dob_year']);
     }
     if (!empty($externalVisitor['user_register_date'])) {
         $writer->set('register_date', $externalVisitor['user_register_date']);
     }
     $userExternalModel->bdApiConsumer_syncUpOnRegistration($writer, $externalToken, $externalVisitor);
     $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);
     // TODO: option for extra user group
     $writer->preSave();
     if ($writer->hasErrors()) {
         return $user;
     }
     try {
         $writer->save();
         $user = $writer->getMergedData();
         $userExternalModel->bdApiConsumer_updateExternalAuthAssociation($provider, $externalVisitor['user_id'], $user['user_id'], array_merge($externalVisitor, array('token' => $externalToken)));
         XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register_api_consumer');
     } catch (XenForo_Exception $e) {
         XenForo_Error::logException($e, false);
     }
     return $user;
 }
Example #2
0
 /**
  *
  * @see XenForo_DataWriter_User::_preSave()
  */
 protected function _preSave()
 {
     if ($this->getOption(self::OPTION_ADMIN_EDIT) && $this->isInsert() && !$this->get('password')) {
         $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
         $this->set('scheme_class', $auth->getClassName());
         $this->set('data', $auth->generate(''), 'xf_user_authenticate');
     }
     parent::_preSave();
 }
Example #3
0
 /**
  * Returns an auth object based on an input userid
  *
  * @param integer Userid
  *
  * @return XenForo_Authentication_Abstract false
  */
 public function getParentAuthenticationObjectByEmail($email)
 {
     $authenticate = $this->getParentAuthenticationRecordByEmail($email);
     if (!$authenticate) {
         return false;
     }
     $auth = XenForo_Authentication_Abstract::create($authenticate['parent_scheme_class']);
     if (!$auth) {
         return false;
     }
     $auth->setData($authenticate['parent_data']);
     return $auth;
 }
 /**
  * Resets the specified user's parental control password and emails the password to the parent if requested.
  *
  * @param integer $userId
  * @param boolean $sendEmail
  *
  * @return string New password
  */
 public function resetParentPassword($userId, $sendEmail = true)
 {
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $dw->setExistingData($userId);
     $password = XenForo_Application::generateRandomString(8);
     $auth = XenForo_Authentication_Abstract::createDefault();
     $dw->set('parent_scheme_class', $auth->getClassName());
     $dw->set('parent_data', $auth->generate($password));
     $dw->save();
     $user = $dw->getMergedData();
     if ($sendEmail) {
         $params = array('user' => $user, 'password' => $password, 'boardTitle' => XenForo_Application::get('options')->boardTitle, 'boardUrl' => XenForo_Application::get('options')->boardUrl);
         $mail = XenForo_Mail::create('th_lost_password_reset_parentalcontrol', $params, $user['language_id']);
         $mail->send($user['parent_email'], (string) new XenForo_Phrase('th_parent_of_x_parentalcontrol', array('username' => $user['username'])));
     }
     return $password;
 }
Example #5
0
 /**
  * Sets the user's password.
  *
  * @param string $password
  * @param string|false $passwordConfirm If a string, ensures that the password and the confirm are the same
  * @param XenForo_Authentication_Abstract|null $auth Auth object to generate the password (or null to use default)
  * @param boolean If true, do not accept an empty password
  *
  * @return boolean
  */
 public function setPassword($password, $passwordConfirm = false, XenForo_Authentication_Abstract $auth = null, $requirePassword = false)
 {
     if ($requirePassword && $password === '') {
         return new XenForo_Phrase('please_enter_valid_password');
     }
     if ($passwordConfirm !== false && $password !== $passwordConfirm) {
         return new XenForo_Phrase('passwords_did_not_match');
     }
     if (!$auth) {
         $auth = XenForo_Authentication_Abstract::createDefault();
     }
     $authData = $auth->generate($password);
     if (!$authData) {
         return new XenForo_Phrase('please_enter_valid_password');
     }
     return array('scheme_class' => $auth->getClassName(), 'data' => $authData);
 }
Example #6
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;
 }
Example #7
0
 /**
  * Sets the user's password.
  *
  * @param string $password
  * @param string|false $passwordConfirm If a string, ensures that the password and the confirm are the same
  * @param XenForo_Authentication_Abstract|null $auth Auth object to generate the password (or null to use default)
  * @param boolean If true, do not accept an empty password
  *
  * @return boolean
  */
 public function setPassword($password, $passwordConfirm = false, XenForo_Authentication_Abstract $auth = null, $requirePassword = false)
 {
     if ($requirePassword && $password === '') {
         $this->error(new XenForo_Phrase('please_enter_valid_password'), 'password');
         return false;
     }
     if ($passwordConfirm !== false && $password !== $passwordConfirm) {
         $this->error(new XenForo_Phrase('passwords_did_not_match'), 'password');
         return false;
     }
     if (!$auth) {
         $auth = XenForo_Authentication_Abstract::createDefault();
     }
     $authData = $auth->generate($password);
     if (!$authData) {
         $this->error(new XenForo_Phrase('please_enter_valid_password'), 'password');
         return false;
     }
     $this->set('scheme_class', $auth->getClassName());
     $this->set('data', $authData, 'xf_user_authenticate');
     return true;
 }
 /**
  * Resets the specified user's password and emails the password to them if requested.
  *
  * @param integer $userId
  * @param boolean $sendEmail
  *
  * @return string New password
  */
 public function resetPassword($userId, $sendEmail = true)
 {
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $dw->setExistingData($userId);
     $password = XenForo_Application::generateRandomString(8);
     $password = strtr($password, array('I' => 'i', 'l' => 'L', '0' => 'O', 'o' => 'O'));
     $password = trim($password, '_-');
     $auth = XenForo_Authentication_Abstract::createDefault();
     $dw->set('scheme_class', $auth->getClassName());
     $dw->set('data', $auth->generate($password));
     $dw->save();
     $user = $dw->getMergedData();
     if ($sendEmail) {
         $params = array('user' => $user, 'password' => $password, 'boardTitle' => XenForo_Application::get('options')->boardTitle, 'boardUrl' => XenForo_Application::get('options')->boardUrl);
         $mail = XenForo_Mail::create('user_lost_password_reset', $params, $user['language_id']);
         $mail->send($user['email'], $user['username']);
     }
     return $password;
 }
Example #9
0
 /**
  * Returns an auth object based on an input userid
  *
  * @param integer Userid
  *
  * @return XenForo_Authentication_Abstract|false
  */
 public function getUserAuthenticationObjectByUserId($userId)
 {
     $authenticate = $this->getUserAuthenticationRecordByUserId($userId);
     if (!$authenticate) {
         return false;
     }
     $auth = XenForo_Authentication_Abstract::create($authenticate['scheme_class']);
     if (!$auth) {
         return false;
     }
     $auth->setData($authenticate['data']);
     return $auth;
 }
Example #10
0
File: User.php Project: sushj/bdApi
 public function actionPostIndex()
 {
     /* @var $oauth2Model bdApi_Model_OAuth2 */
     $oauth2Model = $this->getModelFromCache('bdApi_Model_OAuth2');
     /* @var $userConfirmationModel XenForo_Model_UserConfirmation */
     $userConfirmationModel = $this->getModelFromCache('XenForo_Model_UserConfirmation');
     /* @var $session bdApi_Session */
     $session = XenForo_Application::getSession();
     $clientId = $session->getOAuthClientId();
     $clientSecret = $session->getOAuthClientSecret();
     if (empty($clientId) or empty($clientSecret)) {
         $clientId = $this->_input->filterSingle('client_id', XenForo_Input::STRING);
         $client = $oauth2Model->getClientModel()->getClientById($clientId);
         if (empty($client)) {
             return $this->responseError(new XenForo_Phrase('bdapi_post_slash_users_requires_client_id'), 400);
         }
         $clientSecret = $client['client_secret'];
     }
     $input = $this->_input->filter(array('user_email' => XenForo_Input::STRING, 'username' => XenForo_Input::STRING, 'password' => XenForo_Input::STRING, 'password_algo' => XenForo_Input::STRING, 'user_dob_day' => XenForo_Input::UINT, 'user_dob_month' => XenForo_Input::UINT, 'user_dob_year' => XenForo_Input::UINT));
     if (empty($input['user_email'])) {
         // backward compatibility
         $input['user_email'] = $this->_input->filterSingle('email', XenForo_Input::STRING);
     }
     $extraInput = $this->_input->filter(array('extra_data' => XenForo_Input::STRING, 'extra_timestamp' => XenForo_Input::UINT));
     if (!empty($extraInput['extra_data'])) {
         $extraData = bdApi_Crypt::decryptTypeOne($extraInput['extra_data'], $extraInput['extra_timestamp']);
         if (!empty($extraData)) {
             $extraData = @unserialize($extraData);
         }
         if (empty($extraData)) {
             $extraData = array();
         }
     }
     $userModel = $this->_getUserModel();
     $options = XenForo_Application::getOptions();
     $session = XenForo_Application::getSession();
     $visitor = XenForo_Visitor::getInstance();
     /* @var $writer XenForo_DataWriter_User */
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $registrationDefaults = $options->get('registrationDefaults');
     if (!empty($registrationDefaults)) {
         $writer->bulkSet($registrationDefaults, array('ignoreInvalidFields' => true));
     }
     $writer->set('email', $input['user_email']);
     $writer->set('username', $input['username']);
     $password = bdApi_Crypt::decrypt($input['password'], $input['password_algo'], $clientSecret);
     if (!empty($password)) {
         $writer->setPassword($password, $password);
     } else {
         // no password or unable to decrypt password
         // create new user with no password auth scheme
         $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
         $writer->set('scheme_class', $auth->getClassName());
         $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
     }
     if ($options->get('gravatarEnable') && XenForo_Model_Avatar::gravatarExists($input['user_email'])) {
         $writer->set('gravatar', $input['user_email']);
     }
     $writer->set('dob_day', $input['user_dob_day']);
     $writer->set('dob_month', $input['user_dob_month']);
     $writer->set('dob_year', $input['user_dob_year']);
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $allowEmailConfirm = true;
     if (!empty($extraData['user_email']) && $extraData['user_email'] == $writer->get('email')) {
         // the email address has been validated by some other mean (external provider?)
         // do not require email confirmation again to avoid complication
         $allowEmailConfirm = false;
     }
     $writer->advanceRegistrationUserState($allowEmailConfirm);
     if ($visitor->hasAdminPermission('user') and $session->checkScope(bdApi_Model_OAuth2::SCOPE_MANAGE_SYSTEM)) {
         $writer->set('user_state', 'valid');
     }
     $writer->save();
     $user = $writer->getMergedData();
     // log the ip of the user registering
     XenForo_Model_Ip::log(XenForo_Visitor::getUserId() ? XenForo_Visitor::getUserId() : $user['user_id'], 'user', $user['user_id'], 'register');
     if ($user['user_state'] == 'email_confirm') {
         $userConfirmationModel->sendEmailConfirmation($user);
     }
     if (!empty($extraData['external_provider']) && !empty($extraData['external_provider_key'])) {
         /* @var $userExternalModel XenForo_Model_UserExternal */
         $userExternalModel = $this->getModelFromCache('XenForo_Model_UserExternal');
         $userExternalModel->updateExternalAuthAssociation($extraData['external_provider'], $extraData['external_provider_key'], $user['user_id']);
     }
     if (XenForo_Visitor::getUserId() == 0) {
         XenForo_Visitor::setup($user['user_id']);
     }
     $scopes = $oauth2Model->getSystemSupportedScopes();
     $scopes = bdApi_Template_Helper_Core::getInstance()->scopeJoin($scopes);
     $token = $oauth2Model->getServer()->createAccessToken($clientId, $user['user_id'], $scopes);
     $user = $userModel->getUserById($user['user_id'], $userModel->getFetchOptionsToPrepareApiData());
     $data = array('user' => $this->_filterDataSingle($this->_getUserModel()->prepareApiDataForUser($user)), '_user' => $user, 'token' => $token);
     return $this->responseData('bdApi_ViewApi_User_Single', $data);
 }
Example #11
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());
 }
 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());
 }
Example #13
0
 public function massImportUsers(array $users, &$errors = array())
 {
     $db = $this->_getDb();
     foreach ($users as $userId => $user) {
         $existingUser = array();
         if (!empty($user['email'])) {
             $existingUser = $this->getUserByEmail($user['email']);
         }
         /* @var $dw XenForo_DataWriter_User */
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
         $dw->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
         $xenOptions = XenForo_Application::get('options');
         if (isset($user['user_id']) && $xenOptions->th_userImpEx_allowUserIdSet) {
             $dw->disableUserIdVerification();
         }
         if ($existingUser) {
             $dw->setExistingData($existingUser);
         }
         if (!empty($user['custom_fields']) && is_array($user['custom_fields'])) {
             $dw->setCustomFields($user['custom_fields']);
             unset($user['custom_fields']);
         }
         if (isset($user['password'])) {
             $dw->setPassword($user['password']);
             unset($user['password']);
         } elseif ($dw->isInsert()) {
             if ($xenOptions->th_userImpEx_randomPassword) {
                 $password = XenForo_Application::generateRandomString(8);
                 $password = strtr($password, array('I' => 'i', 'l' => 'L', '0' => 'O', 'o' => 'O'));
                 $password = trim($password, '_-');
                 $dw->setPassword($password);
             }
             $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
             $dw->set('scheme_class', $auth->getClassName());
             $dw->set('data', $auth->generate(''), 'xf_user_authenticate');
         }
         if (!isset($user['user_group_id']) && $dw->isInsert()) {
             $dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
         }
         if (!isset($user['language_id']) && $dw->isInsert()) {
             $dw->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
         }
         $fieldNames = $dw->getFieldNames();
         foreach ($fieldNames as $fieldName) {
             if (isset($user[$fieldName])) {
                 $dw->set($fieldName, $user[$fieldName]);
             }
         }
         $dwErrors = $dw->getErrors();
         if ($dwErrors) {
             $users[$userId]['dwErrors'] = $dwErrors;
         } else {
             $dw->preSave();
             $dwErrors = $dw->getErrors();
             if ($dwErrors) {
                 $users[$userId]['dwErrors'] = $dwErrors;
             } else {
                 unset($users[$userId]);
                 $dw->save();
             }
         }
     }
     return $users;
 }
Example #14
0
 /**
  * Sets the parent's password.
  *
  * @param string $password
  * @param string|false $passwordConfirm If a string, ensures that the
  * password and the confirm are the same
  *
  * @return boolean
  */
 public function setParentPassword($password, $passwordConfirm = false)
 {
     if ($passwordConfirm !== false && $password !== $passwordConfirm) {
         $this->error(new XenForo_Phrase('passwords_did_not_match'), 'password');
         return false;
     }
     $auth = XenForo_Authentication_Abstract::createDefault();
     $authData = $auth->generate($password);
     if (!$authData) {
         $this->error(new XenForo_Phrase('please_enter_valid_password'), 'password');
         return false;
     }
     $this->set('parent_scheme_class', $auth->getClassName());
     $this->set('parent_data', $authData);
     return true;
 }