Esempio n. 1
0
 /**
  * Override avatar upload to support avatar gallery selection
  */
 public function actionAvatarUpload()
 {
     // Receive input data
     $inputData = $this->_input->filter(array('delete' => XenForo_Input::UINT, 'avatar_crop_x' => XenForo_Input::UINT, 'avatar_crop_y' => XenForo_Input::UINT, 'gravatar' => XenForo_Input::STRING, 'chosen_avatar' => XenForo_Input::STRING, 'use_gravatar' => XenForo_Input::UINT));
     // No point in overriding the default behaviour if the user didn't use an avatar from the gallery
     if ($inputData['use_gravatar'] == 1 or empty($inputData['chosen_avatar'])) {
         return parent::actionAvatarUpload();
     }
     // Locate avatar
     $options = XenForo_Application::get('options');
     $path = dirname(__FILE__) . '/../../..' . $options->avatarGalleryPath;
     $avatar = $path . '/' . $inputData['chosen_avatar'];
     // Validate it exists and is readable
     if (!file_exists($avatar) or !is_readable($avatar)) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     // Get image attributes
     list($width, $height, $type, $attr) = getimagesize($avatar);
     // Copy the image to a temp dir, since we're hooking into the avatar upload functionality
     $filename = sys_get_temp_dir() . '/' . uniqid();
     copy($avatar, $filename);
     $visitor = XenForo_Visitor::getInstance();
     // Apply the avatar to the user
     $avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');
     $avatarData = $avatarModel->applyAvatar($visitor['user_id'], $filename, $type, $width, $height, $visitor->getPermissions());
     // merge new data into $visitor, if there is any
     if (isset($avatarData) && is_array($avatarData)) {
         foreach ($avatarData as $key => $val) {
             $visitor[$key] = $val;
         }
     }
     $message = new XenForo_Phrase('upload_completed_successfully');
     // return a view if noredirect has been requested and we are not deleting
     if ($this->_noRedirect()) {
         return $this->responseView('XenForo_ViewPublic_Account_AvatarUpload', 'account_avatar_upload', array('user' => $visitor->toArray(), 'sizeCode' => 'm', 'maxWidth' => XenForo_Model_Avatar::getSizeFromCode('m'), 'maxDimension' => $visitor['avatar_width'] > $visitor['avatar_height'] ? 'height' : 'width', 'width' => $visitor['avatar_width'], 'height' => $visitor['avatar_height'], 'cropX' => $visitor['avatar_crop_x'], 'cropY' => $visitor['avatar_crop_y'], 'user_id' => $visitor['user_id'], 'avatar_date' => $visitor['avatar_date'], 'gravatar' => $visitor['gravatar'], 'message' => $message));
     } else {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('account/personal-details'), $message);
     }
 }
Esempio n. 2
0
 /**
  * Registers a new user.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionRegister()
 {
     $this->_assertPostOnly();
     $this->_assertRegistrationActive();
     $inputData = $this->_getRegistrationInputDataSafe();
     $data = $inputData['data'];
     $passwords = $inputData['passwords'];
     $customFields = $inputData['customFields'];
     $customFieldsShown = $inputData['customFieldsShown'];
     $errors = $inputData['errors'];
     $options = XenForo_Application::getOptions();
     if (!XenForo_Captcha_Abstract::validateDefault($this->_input)) {
         $errors[] = new XenForo_Phrase('did_not_complete_the_captcha_verification_properly');
     }
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         $errors[] = new XenForo_Phrase('you_must_agree_to_terms_of_service');
     }
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     $writer->bulkSet($data);
     $writer->setPassword($passwords['password'], $passwords['password_confirm'], null, true);
     // if the email corresponds to an existing Gravatar, use it
     if ($this->_canApplyAvatar() && $options->gravatarEnable && XenForo_Model_Avatar::gravatarExists($data['email'])) {
         $writer->set('gravatar', $data['email']);
     }
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $writer->setCustomFields($customFields, $customFieldsShown);
     if (!$this->_validateBirthdayInput($writer, $birthdayError)) {
         $errors[] = $birthdayError;
     }
     $registerTime = XenForo_Application::getSession()->get('registrationTime');
     if (!$registerTime || $registerTime + $options->get('registrationTimer') > time()) {
         $errors[] = new XenForo_Phrase('sorry_you_must_wait_longer_to_create_account');
     }
     $regKey = XenForo_Application::getSession()->get('registrationKey');
     if (!$regKey || $regKey != $this->_input->filterSingle('reg_key', XenForo_Input::STRING)) {
         $errors[] = new XenForo_Phrase('something_went_wrong_please_try_again');
     }
     $spamModel = $this->_runSpamCheck($writer, $errors);
     $writer->advanceRegistrationUserState();
     $writer->preSave();
     $errors = array_merge($errors, $writer->getErrors());
     if ($errors) {
         $fields = $data;
         $fields['tos'] = $this->_input->filterSingle('agree', XenForo_Input::UINT);
         $fields['custom_fields'] = $customFields;
         return $this->_getRegisterFormResponse($fields, $errors);
     }
     $writer->save();
     $user = $writer->getMergedData();
     $spamModel->logSpamTrigger('user', $user['user_id']);
     if ($user['user_state'] == 'email_confirm') {
         $this->_getUserConfirmationModel()->sendEmailConfirmation($user);
     }
     return $this->_completeRegistration($user);
 }
Esempio n. 3
0
 /**
  * TODO
  */
 public function register($user_data)
 {
     if (empty($user_data['username'])) {
         // Username was empty, return error.
         return array('error' => 10, 'errors' => 'Missing required parameter: username');
     } else {
         if (empty($user_data['password'])) {
             // Password was empty, return error.
             return array('error' => 10, 'errors' => 'Missing required parameter: password');
         } else {
             if (empty($user_data['email'])) {
                 // Email was empty, return error.
                 return array('error' => 10, 'errors' => 'Missing required parameter: email');
             }
         }
     }
     $usr = $this->getUser($user_data['username']);
     if ($usr->isRegistered()) {
         if ($usr->getEmail() != $user_data['email']) {
             $edit_results = $this->editUser($usr, array('email' => $user_data['email'], 'user_state' => 'email_confirm'));
             if (!empty($edit_results['error'])) {
                 return $edit_results;
             } else {
                 $user = $this->getUser($user_data['username']);
                 XenForo_Model::create('XenForo_Model_UserConfirmation')->sendEmailConfirmation($user->getData());
                 return $user->getData();
             }
         } else {
             return array('error' => 40, 'errors' => 'User already exists');
         }
     } else {
         // Create a new variable for the password.
         $password = $user_data['password'];
         // Unset the password from the user data array.
         unset($user_data['password']);
         if (!empty($user_data['ip_address'])) {
             // Create a new variable for the ip address.
             $ip_address = $user_data['ip_address'];
             // Unset the ip address from the user data array.
             unset($user_data['ip_address']);
         }
         // Get the default options from XenForo.
         $options = XenForo_Application::get('options');
         // Create the data writer object for registrations, and set the defaults.
         $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
         if ($options->registrationDefaults) {
             // Set the default registration options if it's set in the XenForo options.
             $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => TRUE));
         }
         if (!empty($user_data['group_id'])) {
             // Group ID is set.
             $writer->set('user_group_id', $user_data['group_id']);
             // We need to unset the group id as we don't want it to be included into the bulk set.
             unset($user_data['group_id']);
         } else {
             // Group ID is not set, default back to default.
             $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
         }
         if (!empty($user_data['user_state'])) {
             // User state is set.
             $writer->set('user_state', $user_data['user_state']);
         } else {
             // User state is not set, default back to default.
             $writer->advanceRegistrationUserState();
         }
         if (!empty($user_data['language_id'])) {
             // Language ID is set.
             $writer->set('language_id', $user_data['language_id']);
         } else {
             // Language ID is not set, default back to default.
             $writer->set('language_id', $options->defaultLanguageId);
         }
         if (!empty($user_data['custom_fields'])) {
             // Custom fields are set.
             // Check if there are any custom fields in the data array.
             if (count($user_data['custom_fields']) > 0) {
                 // There were one or more custom fields set, set them in the writer.
                 $writer->setCustomFields($user_data['custom_fields']);
             }
             // We need to unset the custom fields as we don't want it to be included into the bulk set.
             unset($user_data['custom_fields']);
         }
         if (!empty($user_data['add_groups'])) {
             // Add group is set.
             // Check if there are any custom fields in the data array.
             if (!is_array($user_data['add_groups']) || count($user_data['add_groups']) == 0) {
                 // The edit failed, return errors.
                 return array('error' => 7, 'errors' => 'The add_groups parameter needs to be an array and have at least 1 item.');
             }
             // Set the secondary group(s) of the user.
             $writer->setSecondaryGroups($user_data['add_groups']);
             // We need to unset the group id as we don't want it to be included into the bulk set.
             unset($user_data['add_groups']);
         }
         // Check if Gravatar is enabled, set the gravatar if it is and there's a gravatar for the email.
         if ($options->gravatarEnable && XenForo_Model_Avatar::gravatarExists($data['email'])) {
             $writer->set('gravatar', $user_data['email']);
         }
         // Set the data for the data writer.
         $writer->bulkSet($user_data);
         // Set the password for the data writer.
         $writer->setPassword($password, $password);
         // Pre save the data.
         $writer->preSave();
         if ($writer->hasErrors()) {
             // The registration failed, return errors.
             return array('error' => TRUE, 'errors' => $writer->getErrors());
         }
         // Save the user to the database.
         $writer->save();
         // Get the User as a variable:
         $user = $writer->getMergedData();
         // Check if IP is set.
         if (!empty($user_data['ip_address'])) {
             // Log the IP of the user that registered.
             XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register', $ip_address);
         }
         if ($user['user_state'] == 'email_confirm') {
             XenForo_Model::create('XenForo_Model_UserConfirmation')->sendEmailConfirmation($user);
         } else {
             if ($user['user_state'] == 'valid') {
                 XenForo_Model::create('XenForo_Model_UserConfirmation')->resetPassword($user['user_id'], true);
             }
         }
         return $user;
     }
 }
Esempio n. 4
0
    protected function _importUser(array $user, array $options)
    {
        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        if ($this->_groupMap === null) {
            $this->_groupMap = $this->_importModel->getImportContentMap('userGroup');
        }
        if ($this->_userActivationSetting === null) {
            $this->_userActivationSetting = $sDb->fetchOne('
				SELECT value
				FROM ' . $prefix . 'settings
				WHERE name = \'registration_method\'
			');
        }
        $secondaryGroupIds = array();
        if (!empty($user['additional_groups'])) {
            $secondaryGroupIds = explode(',', $user['additional_groups']);
            $secondaryGroupIds[] = $user['id_post_group'];
        }
        $user['ban'] = $this->_getUserBan($user);
        // This is pretty much a best effort though should be roughly accurate based on what we know.
        $timeZone = $sDb->fetchOne('
			SELECT value
			FROM ' . $this->_prefix . 'settings
			WHERE variable = \'default_timezone\'
		');
        if ($timeZone) {
            $timeZone = explode('GMT', $timeZone);
            if (isset($timeZone[1])) {
                $timeZone = $timeZone[1];
            } else {
                $timeZone = 0;
            }
        } else {
            $timeZone = 0;
        }
        $timeZoneOffset = $timeZone + $user['time_offset'];
        $import = array('username' => $this->_convertToUtf8($user['member_name'], true), 'email' => $this->_convertToUtf8($user['email_address'], true), 'user_group_id' => XenForo_Model_User::$defaultRegisteredGroupId, 'secondary_group_ids' => $this->_mapLookUpList($this->_groupMap, $secondaryGroupIds, false), 'authentication' => array('scheme_class' => 'XenForo_Authentication_SMF', 'data' => array('hash' => $user['passwd'], 'username' => strtolower($user['member_name']))), 'last_activity' => $user['last_login'], 'register_date' => $user['date_registered'], 'ip' => $user['member_ip'], 'homepage' => $this->_convertToUtf8($user['website_url'], true), 'message_count' => $user['posts'], 'is_admin' => $user['id_group'] == 1 ? 1 : 0, 'is_banned' => $user['ban'] ? 1 : 0, 'signature' => $this->_sanitizeBbCode($user['signature']), 'timezone' => $this->_importModel->resolveTimeZoneOffset($timeZoneOffset, false), 'visible' => $user['show_online'], 'content_show_signature' => true, 'receive_admin_email' => $user['notify_announcements'], 'allow_send_personal_conversation' => 'everyone', 'email_on_conversation' => $user['pm_email_notify'] ? 1 : 0, 'user_state' => $user['is_activated'] == 1 ? 'valid' : 'moderated', 'gender' => $user['gender'] == 1 ? 'male' : ($user['gender'] == 2 ? 'female' : ''), 'custom_title' => $this->_convertToUtf8($user['personal_text'], true));
        if ($user['birthdate']) {
            $parts = explode('-', $user['birthdate']);
            if (count($parts) == 3) {
                // Default birth year.
                if (trim($parts[2]) != '0001') {
                    $import['dob_day'] = trim($parts[0]);
                    $import['dob_month'] = trim($parts[1]);
                    $import['dob_year'] = trim($parts[2]);
                }
            }
        }
        if (!empty($options['gravatar'])) {
            if (!$user['avatar'] && $user['email_address'] && $user['posts'] && XenForo_Model_Avatar::gravatarExists($user['email_address'])) {
                $import['gravatar'] = $import['email'];
            }
        }
        $import['about'] = $this->_convertToUtf8($user['personal_text'], true);
        $import['location'] = $this->_convertToUtf8($user['location'], true);
        if ($user['website_url'] && Zend_Uri::check($user['website_url'])) {
            $import['homepage'] = $user['website_url'];
        }
        // custom user fields
        $userFieldDefinitions = $this->_importModel->getUserFieldDefinitions();
        $identityMap = array('icq' => 'icq', 'aim' => 'aim', 'yahoo' => 'yim', 'msn' => 'msn');
        foreach ($identityMap as $identityType => $smfField) {
            if (isset($userFieldDefinitions[$identityType])) {
                $import[XenForo_Model_Import::USER_FIELD_KEY][$identityType] = $this->_convertToUtf8($user[$smfField], true);
            }
        }
        if ($import['is_admin']) {
            // give all admin permissions
            $adminPerms = XenForo_Model::create('XenForo_Model_Admin')->getAllAdminPermissions();
            $import['admin_permissions'] = array_keys($adminPerms);
        }
        $importedUserId = $this->_importModel->importUser($user['id_member'], $import, $failedKey);
        if ($importedUserId) {
            if ($user['ban']) {
                $this->_importModel->importBan(array('user_id' => $importedUserId, 'ban_user_id' => 0, 'ban_date' => $user['ban']['ban_time'], 'end_date' => $user['ban']['expire_time'], 'user_reason' => $this->_convertToUtf8($user['ban']['reason'], true)));
            }
            if ($user['buddy_list']) {
                $this->_session->setExtraData('userFollowing', $importedUserId, $user['buddy_list']);
            }
            if ($user['pm_ignore_list']) {
                $this->_session->setExtraData('userIgnored', $importedUserId, $user['pm_ignore_list']);
            }
        } else {
            if ($failedKey) {
                $this->_session->setExtraData('userFailed', $user['id_member'], $failedKey);
            }
        }
        return $importedUserId;
    }
Esempio n. 5
0
    protected function _importUser(array $user, array $options)
    {
        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        if ($this->_groupMap === null) {
            $this->_groupMap = $this->_importModel->getImportContentMap('userGroup');
        }
        if ($this->_userFieldMap === null) {
            $this->_userFieldMap = $this->_importModel->getImportContentMap('userField');
        }
        if ($this->_userActivationSetting === null) {
            $this->_userActivationSetting = $sDb->fetchOne('
				SELECT config_value
				FROM ' . $prefix . 'config
				WHERE config_name = \'require_activation\'
			');
        }
        if ($user['user_type'] == 2) {
            return false;
            // ignore this user
        }
        $groups = $sDb->fetchCol('
			SELECT group_id
			FROM ' . $prefix . 'user_group
			WHERE user_id = ' . $sDb->quote($user['user_id']) . '
				AND group_id <> ' . $sDb->quote($user['group_id']) . '
				AND user_pending = 0
		');
        $user['user_options'] = intval($user['user_options']);
        $import = array('username' => $this->_convertToUtf8($user['username'], true), 'email' => $this->_convertToUtf8($user['user_email'], true), 'user_group_id' => $this->_mapLookUp($this->_groupMap, $user['group_id'], XenForo_Model_User::$defaultRegisteredGroupId), 'secondary_group_ids' => $this->_mapLookUpList($this->_groupMap, $groups), 'authentication' => array('scheme_class' => 'XenForo_Authentication_PhpBb3', 'data' => array('hash' => $user['user_password'])), 'last_activity' => $user['user_lastvisit'], 'register_date' => $user['user_regdate'], 'ip' => $user['user_ip'], 'homepage' => $this->_convertToUtf8($user['user_website'], true), 'message_count' => $user['user_posts'], 'is_admin' => $user['user_type'] == 3 ? 1 : 0, 'is_banned' => $user['ban_id'] ? 1 : 0, 'signature' => $this->_sanitizeBbCode($user['user_sig']), 'timezone' => $this->_importModel->resolveTimeZoneOffset($user['user_timezone'], $user['user_dst']), 'visible' => $user['user_allow_viewonline'], 'content_show_signature' => $user['user_options'] & 1 << 3 ? 1 : 0, 'receive_admin_email' => $user['user_allow_massemail'], 'default_watch_state' => $user['user_notify'] ? 'watch_email' : '', 'allow_send_personal_conversation' => $user['user_allow_pm'] ? 'everyone' : 'none', 'email_on_conversation' => $user['user_notify_pm']);
        if ($user['group_id'] == 3) {
            $import['user_state'] = 'moderated';
        } else {
            if ($user['user_type'] == 1 && $user['user_inactive_reason'] == 1) {
                $import['user_state'] = $this->_userActivationSetting == 2 ? 'moderated' : 'email_confirm';
            } else {
                if ($user['user_type'] == 1 && $user['user_inactive_reason'] == 2) {
                    $import['user_state'] = 'email_confirm_edit';
                } else {
                    $import['user_state'] = 'valid';
                }
            }
        }
        if ($user['user_birthday']) {
            $parts = explode('-', $user['user_birthday']);
            if (count($parts) == 3) {
                $import['dob_day'] = trim($parts[0]);
                $import['dob_month'] = trim($parts[1]);
                $import['dob_year'] = trim($parts[2]);
            }
        }
        // try to give users without an avatar that have actually posted a gravatar
        if (!empty($options['gravatar'])) {
            // 1 = uploaded avatar
            if ($user['user_avatar_type'] != 1 && $user['user_email'] && $user['user_lastpost_time'] && XenForo_Model_Avatar::gravatarExists($user['user_email'])) {
                $import['gravatar'] = $import['email'];
            }
        }
        $import['about'] = $this->_convertToUtf8($user['user_interests'], true);
        $import['location'] = $this->_convertToUtf8($user['user_from'], true);
        $import['occupation'] = $this->_convertToUtf8($user['user_occ'], true);
        // custom user fields
        $userFieldDefinitions = $this->_importModel->getUserFieldDefinitions();
        $identityMap = array('icq' => 'user_icq', 'aim' => 'user_aim', 'yahoo' => 'user_yim', 'msn' => 'user_msnm');
        foreach ($identityMap as $identityType => $phpBbField) {
            if (isset($userFieldDefinitions[$identityType])) {
                $import[XenForo_Model_Import::USER_FIELD_KEY][$identityType] = $this->_convertToUtf8($user[$phpBbField], true);
            }
        }
        $userFieldLookups = $this->_session->getExtraData('userFieldLookups');
        foreach ($this->_userFieldMap as $oldFieldId => $newFieldId) {
            if (!isset($userFieldDefinitions[$newFieldId])) {
                continue;
            }
            $userFieldValue = '';
            if (isset($user["pf_{$oldFieldId}"]) && $user["pf_{$oldFieldId}"] !== '') {
                if (isset($userFieldLookups[$oldFieldId])) {
                    $fieldInfo = $userFieldLookups[$oldFieldId];
                    $fieldChoiceId = max(0, $user["pf_{$oldFieldId}"] - 1);
                    // option ids are 0 keyed, values are 1 keyed
                    if (isset($fieldInfo['choices'][$fieldChoiceId])) {
                        $userFieldValue = $fieldInfo['choices'][$fieldChoiceId];
                    }
                } else {
                    // set the field value directly
                    $userFieldValue = $this->_convertToUtf8($user["pf_{$oldFieldId}"], true);
                }
            }
            $import[XenForo_Model_Import::USER_FIELD_KEY][$newFieldId] = $userFieldValue;
        }
        if ($import['is_admin']) {
            // give all admin permissions
            $adminPerms = XenForo_Model::create('XenForo_Model_Admin')->getAllAdminPermissions();
            $import['admin_permissions'] = array_keys($adminPerms);
        }
        $importedUserId = $this->_importModel->importUser($user['user_id'], $import, $failedKey);
        if ($importedUserId) {
            if ($user['ban_id']) {
                $this->_importModel->importBan(array('user_id' => $importedUserId, 'ban_user_id' => 0, 'ban_date' => $user['ban_start'], 'end_date' => $user['ban_end'], 'user_reason' => $this->_convertToUtf8($user['ban_give_reason'], true)));
            }
            // TODO: this doesn't necessarily work, as the users may not be imported yet.
            // It could work with maintained user IDs though.
            $friends = array();
            $foes = array();
            $zebraResults = $sDb->query('
				SELECT zebra_id, friend, foe
				FROM ' . $prefix . 'zebra
				WHERE user_id = ' . $sDb->quote($user['user_id']));
            while ($zebra = $zebraResults->fetch()) {
                if ($zebra['foe']) {
                    $foes[] = $zebra['zebra_id'];
                }
                if ($zebra['friend']) {
                    $friends[] = $zebra['zebra_id'];
                }
            }
            if ($friends) {
                $friends = $this->_importModel->getImportContentMap('user', $friends);
                $this->_importModel->importFollowing($importedUserId, $friends);
            }
            if ($foes) {
                $foes = $this->_importModel->getImportContentMap('user', $foes);
                $this->_importModel->importIgnored($importedUserId, $foes);
            }
        } else {
            if ($failedKey) {
                $this->_session->setExtraData('userFailed', $user['user_id'], $failedKey);
            }
        }
        return $importedUserId;
    }
Esempio n. 6
0
File: User.php Progetto: 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);
 }
Esempio n. 7
0
 /**
  * Returns a Gravatar URL for the user
  *
  * @param array $user
  * @param string|integer $size (s,m,l)
  * @param string Override default (useful to use '404')
  */
 protected static function _getGravatarUrl(array $user, $size, $default = '')
 {
     $md5 = md5($user['gravatar']);
     if ($default === '') {
         $default = '&d=' . urlencode(XenForo_Application::get('options')->boardUrl . '/' . self::_getDefaultAvatarUrl($user, $size));
     } else {
         if (!empty($default)) {
             $default = '&d=' . urlencode($default);
         }
     }
     if (is_string($size)) {
         $size = XenForo_Model_Avatar::getSizeFromCode($size);
     }
     return "http://www.gravatar.com/avatar/{$md5}.jpg?s={$size}{$default}";
 }
Esempio n. 8
0
 protected function _importUser(array $user, array $options)
 {
     if ($this->_groupMap === null) {
         $this->_groupMap = $this->_importModel->getImportContentMap('userGroup');
     }
     if ($this->_userFieldMap === null) {
         $this->_userFieldMap = $this->_importModel->getImportContentMap('userField');
     }
     $user['options'] = intval($user['options']);
     $import = array('username' => $this->_convertToUtf8($user['username'], true), 'email' => $this->_convertToUtf8($user['email']), 'user_group_id' => $this->_mapLookUp($this->_groupMap, $user['usergroupid'], XenForo_Model_User::$defaultRegisteredGroupId), 'secondary_group_ids' => $this->_mapLookUpList($this->_groupMap, explode(',', $user['membergroupids'])), 'authentication' => array('scheme_class' => 'XenForo_Authentication_vBulletin', 'data' => array('hash' => $user['password'], 'salt' => $user['salt'])), 'homepage' => $this->_convertToUtf8($user['homepage']), 'last_activity' => $user['lastactivity'], 'register_date' => $user['joindate'], 'ip' => $user['ipaddress'], 'message_count' => $user['posts'], 'is_admin' => $user['is_admin'], 'is_banned' => $user['is_banned'], 'warning_points' => isset($user['ipoints']) ? $user['ipoints'] : 0, 'signature' => $this->_convertToUtf8($user['signature']), 'timezone' => $this->_importModel->resolveTimeZoneOffset($user['timezoneoffset'], $user['options'] & 64), 'content_show_signature' => $user['options'] & 1 ? 1 : 0, 'receive_admin_email' => $user['options'] & 16 ? 1 : 0);
     if ($user['customtitle']) {
         $import['custom_title'] = $this->_convertToUtf8($user['usertitle']);
         if ($user['customtitle'] == 2) {
             $import['custom_title'] = htmlspecialchars_decode($import['custom_title']);
             $import['custom_title'] = preg_replace('#<br\\s*/?>#i', ', ', $import['custom_title']);
             $import['custom_title'] = strip_tags($import['custom_title']);
         }
     }
     if (!($user['options'] & 2048)) {
         $import['allow_send_personal_conversation'] = 'none';
     } else {
         if ($user['options'] & 131072) {
             $import['allow_send_personal_conversation'] = 'followed';
         }
     }
     if (!($user['options'] & 8388608)) {
         $import['allow_post_profile'] = 'none';
     } else {
         if ($user['options'] & 16777216) {
             $import['allow_post_profile'] = 'followed';
         }
     }
     if ($user['birthday']) {
         $parts = explode('-', $user['birthday']);
         if (count($parts) == 3) {
             $import['dob_day'] = $parts[1];
             $import['dob_month'] = $parts[0];
             $import['dob_year'] = $parts[2] === '0000' ? 0 : $parts[2];
         }
     }
     // try to give users without an avatar that have actually posted a gravatar
     if (!empty($options['gravatar'])) {
         if (!$user['has_custom_avatar'] && $user['email'] && $user['lastpost'] && XenForo_Model_Avatar::gravatarExists($user['email'])) {
             $import['gravatar'] = $import['email'];
         }
     }
     $import['about'] = '';
     if (isset($user['field1'])) {
         $import['about'] .= $this->_convertToUtf8($user['field1'], true) . "\n\n";
     }
     if (isset($user['field3'])) {
         $import['about'] .= $this->_convertToUtf8($user['field3'], true) . "\n\n";
     }
     $import['about'] = trim($import['about']);
     if (isset($user['field2'])) {
         $import['location'] = $this->_convertToUtf8($user['field2'], true);
     }
     if (isset($user['field4'])) {
         $import['occupation'] = $this->_convertToUtf8($user['field4'], true);
     }
     switch ($user['usergroupid']) {
         case 3:
             $import['user_state'] = 'email_confirm';
             break;
         case 4:
             $import['user_state'] = 'moderated';
             break;
         default:
             $import['user_state'] = 'valid';
     }
     switch ($user['autosubscribe']) {
         case -1:
             $import['default_watch_state'] = '';
             break;
         case 0:
             $import['default_watch_state'] = 'watch_no_email';
             break;
         default:
             $import['default_watch_state'] = 'watch_email';
     }
     switch ($user['showbirthday']) {
         case 0:
             $import['show_dob_year'] = 0;
             $import['show_dob_date'] = 0;
             break;
         case 1:
             $import['show_dob_year'] = 1;
             $import['show_dob_date'] = 0;
             break;
         case 2:
             $import['show_dob_year'] = 1;
             $import['show_dob_date'] = 1;
             break;
         case 3:
             $import['show_dob_year'] = 0;
             $import['show_dob_date'] = 1;
             break;
     }
     // custom user fields
     $userFieldDefinitions = $this->_importModel->getUserFieldDefinitions();
     foreach (array('icq', 'aim', 'yahoo', 'msn', 'skype') as $identityType) {
         if (isset($userFieldDefinitions[$identityType])) {
             $import[XenForo_Model_Import::USER_FIELD_KEY][$identityType] = $this->_convertToUtf8($user[$identityType]);
         }
     }
     $userFieldLookups = $this->_session->getExtraData('userFieldLookups');
     foreach ($this->_userFieldMap as $oldFieldId => $newFieldId) {
         if (!isset($userFieldDefinitions[$newFieldId])) {
             continue;
         }
         $userFieldValue = '';
         if ($user["field{$oldFieldId}"] !== '') {
             if (isset($userFieldLookups[$oldFieldId])) {
                 $fieldInfo = $userFieldLookups[$oldFieldId];
                 // use the lookup info to resolve the value
                 if ($fieldInfo['multiple']) {
                     $userFieldValue = array();
                     foreach ($fieldInfo['choices'] as $bitValue => $stringValue) {
                         if ($user["field{$oldFieldId}"] & $bitValue) {
                             $userFieldValue[$stringValue] = $stringValue;
                         }
                     }
                 } else {
                     $fieldChoiceId = $this->_convertToUtf8($user["field{$oldFieldId}"]);
                     if (isset($fieldInfo['choices'][$fieldChoiceId])) {
                         $userFieldValue = $fieldInfo['choices'][$fieldChoiceId];
                     }
                 }
             } else {
                 // set the field value directly
                 $userFieldValue = $this->_convertToUtf8($user["field{$oldFieldId}"], true);
             }
         }
         $import[XenForo_Model_Import::USER_FIELD_KEY][$newFieldId] = $userFieldValue;
     }
     if ($user['is_admin'] && $user['admin_permissions']) {
         $user['admin_permissions'] = intval($user['admin_permissions']);
         $aPerms = array();
         if ($user['admin_permissions'] & 4) {
             $aPerms[] = 'option';
         }
         if ($user['admin_permissions'] & 8) {
             $aPerms[] = 'style';
         }
         if ($user['admin_permissions'] & 16) {
             $aPerms[] = 'language';
         }
         if ($user['admin_permissions'] & 32) {
             $aPerms[] = 'node';
         }
         if ($user['admin_permissions'] & 256) {
             $aPerms[] = 'user';
             $aPerms[] = 'ban';
             $aPerms[] = 'identityService';
             $aPerms[] = 'trophy';
             $aPerms[] = 'userUpgrade';
         }
         if ($user['admin_permissions'] & 512) {
             $aPerms[] = 'userGroup';
         }
         // actually, user permissions
         if ($user['admin_permissions'] & 4096) {
             $aPerms[] = 'bbCodeSmilie';
         }
         if ($user['admin_permissions'] & 8192) {
             $aPerms[] = 'cron';
         }
         if ($user['admin_permissions'] & 16384) {
             $aPerms[] = 'import';
             $aPerms[] = 'upgradeXenForo';
         }
         if ($user['admin_permissions'] & 65536) {
             $aPerms[] = 'addOn';
         }
         $import['admin_permissions'] = $aPerms;
     }
     $importedUserId = $this->_importModel->importUser($user['userid'], $import, $failedKey);
     if ($importedUserId) {
         if ($user['is_banned']) {
             $this->_importModel->importBan(array('user_id' => $importedUserId, 'ban_user_id' => $this->_importModel->mapUserId($user['ban_user_id'], 0), 'ban_date' => $user['ban_date'], 'end_date' => $user['ban_end_date'], 'user_reason' => $this->_convertToUtf8($user['ban_reason'])));
         }
         if ($user['is_super_moderator']) {
             $this->_session->setExtraData('superMods', $user['userid'], $importedUserId);
         }
     } else {
         if ($failedKey) {
             $this->_session->setExtraData('userFailed', $user['userid'], $failedKey);
         }
     }
     return $importedUserId;
 }
Esempio n. 9
0
 public function actionAvatarUpload()
 {
     $this->_assertPostOnly();
     if (!XenForo_Visitor::getInstance()->canUploadAvatar()) {
         return $this->responseNoPermission();
     }
     $avatar = XenForo_Upload::getUploadedFile('avatar');
     /* @var $avatarModel XenForo_Model_Avatar */
     $avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');
     /* @var $visitor XenForo_Visitor */
     $visitor = XenForo_Visitor::getInstance();
     $inputData = $this->_input->filter(array('delete' => XenForo_Input::UINT, 'avatar_crop_x' => XenForo_Input::UINT, 'avatar_crop_y' => XenForo_Input::UINT, 'gravatar' => XenForo_Input::STRING, 'use_gravatar' => XenForo_Input::UINT));
     // upload new avatar
     if ($avatar) {
         $avatarData = $avatarModel->uploadAvatar($avatar, $visitor['user_id'], $visitor->getPermissions());
     } else {
         if ($inputData['delete']) {
             $avatarData = $avatarModel->deleteAvatar(XenForo_Visitor::getUserId());
         } else {
             if (XenForo_Application::get('options')->gravatarEnable && $inputData['use_gravatar']) {
                 if (!$inputData['gravatar']) {
                     $inputData['gravatar'] = $visitor['email'];
                 }
                 if (!XenForo_Model_Avatar::gravatarExists($inputData['gravatar'], $errorText)) {
                     return $this->responseError($errorText);
                 } else {
                     $avatarData = array('gravatar' => $inputData['gravatar']);
                     $this->_saveVisitorSettings($avatarData, $errors);
                 }
             } else {
                 if ($inputData['avatar_crop_x'] != $visitor['avatar_crop_x'] || $inputData['avatar_crop_y'] != $visitor['avatar_crop_y']) {
                     $avatarData = $avatarModel->recropAvatar(XenForo_Visitor::getUserId(), $inputData['avatar_crop_x'], $inputData['avatar_crop_y']);
                 } else {
                     if ($visitor['gravatar'] && !$inputData['use_gravatar']) {
                         $avatarData = array('gravatar' => '');
                         $this->_saveVisitorSettings($avatarData, $errors);
                     }
                 }
             }
         }
     }
     // merge new data into $visitor, if there is any
     if (isset($avatarData) && is_array($avatarData)) {
         foreach ($avatarData as $key => $val) {
             $visitor[$key] = $val;
         }
     }
     $message = new XenForo_Phrase('upload_completed_successfully');
     // return a view if noredirect has been requested and we are not deleting
     if ($this->_noRedirect()) {
         return $this->responseView('XenForo_ViewPublic_Account_AvatarUpload', 'account_avatar_upload', array('user' => $visitor->toArray(), 'sizeCode' => 'm', 'maxWidth' => XenForo_Model_Avatar::getSizeFromCode('m'), 'maxDimension' => $visitor['avatar_width'] > $visitor['avatar_height'] ? 'height' : 'width', 'width' => $visitor['avatar_width'], 'height' => $visitor['avatar_height'], 'cropX' => $visitor['avatar_crop_x'], 'cropY' => $visitor['avatar_crop_y'], 'user_id' => $visitor['user_id'], 'avatar_date' => $visitor['avatar_date'], 'gravatar' => $visitor['gravatar'], 'message' => $message));
     } else {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('account/personal-details'), $message);
     }
 }
Esempio n. 10
0
 public function actionRegister()
 {
     $this->_assertRegistrationActive();
     $vals = $this->_input->filter(array('username' => XenForo_Input::STRING, 'email' => XenForo_Input::STRING, 'password' => XenForo_Input::STRING, 'password_md5' => XenForo_Input::STRING, 'birthday' => XenForo_Input::STRING, 'timezone_name' => XenForo_Input::STRING));
     $options = XenForo_Application::get('options');
     if (!$options->forumrunnerRegistration) {
         $p = new XenForo_Phrase('do_not_have_permission');
         json_error($p->render());
     }
     $out = array();
     if ($vals['username']) {
         $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
         if ($options->registrationDefaults) {
             $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
         }
         $day = $month = $year = '';
         if ($vals['birthday']) {
             $parts = preg_split('#/#', $vals['birthday']);
             if ($parts[0]) {
                 $month = intval($parts[0]);
             }
             if ($parts[1]) {
                 $day = intval($parts[1]);
             }
             if ($parts[2]) {
                 $year = intval($parts[2]);
             }
         }
         // Figure out Time Zone
         $data = array('username' => $vals['username'], 'email' => $vals['email'], 'gender' => '', 'dob_day' => $day, 'dob_month' => $month, 'dob_year' => $year, 'timezone' => $vals['timezone_name']);
         $writer->bulkSet($data);
         $writer->setPassword($vals['password'], $vals['password']);
         // verified by client
         // if the email corresponds to an existing Gravatar, use it
         if ($options->gravatarEnable && XenForo_Model_Avatar::gravatarExists($data['email'])) {
             $writer->set('gravatar', $data['email']);
         }
         $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
         $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
         $writer->advanceRegistrationUserState();
         $writer->preSave();
         if ($options->get('registrationSetup', 'requireDob')) {
             // dob required
             if (!$data['dob_day'] || !$data['dob_month'] || !$data['dob_year']) {
                 $p = new XenForo_Phrase('please_enter_valid_date_of_birth');
                 json_error($p->render());
             }
             $userAge = $this->_getUserProfileModel()->getUserAge($writer->getMergedData(), true);
             if ($userAge < 1) {
                 $p = new XenForo_Phrase('please_enter_valid_date_of_birth');
                 json_error($p->render());
             }
             if ($userAge < intval($options->get('registrationSetup', 'minimumAge'))) {
                 $p = new XenForo_Phrase('sorry_you_too_young_to_create_an_account');
                 json_error($p->render());
             }
         }
         $errors = $writer->getErrors();
         if (count($errors)) {
             // only show first
             $errors = array_values($errors);
             json_error($errors[0]->render());
         }
         $writer->save();
         $user = $writer->getMergedData();
         // log the ip of the user registering
         XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register');
         if ($user['user_state'] == 'email_confirm') {
             $this->_getUserConfirmationModel()->sendEmailConfirmation($user);
             $out['emailverify'] = true;
         } else {
             $out['emailverify'] = false;
         }
         XenForo_Visitor::setup(0);
     } else {
         $p = new XenForo_Phrase('fr_register_forum_rules');
         $out += array('rules' => preg_replace('/<a href=\\"(.*?)\\">(.*?)<\\/a>/', "\\2", $p->render()), 'birthday' => $options->get('registrationSetup', 'requireDob') ? true : false);
     }
     return $out;
 }
Esempio n. 11
0
 /**
  * Registers a new user.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionRegister()
 {
     $this->_assertPostOnly();
     $this->_assertRegistrationActive();
     $errors = array();
     if (!XenForo_Captcha_Abstract::validateDefault($this->_input)) {
         $errors[] = new XenForo_Phrase('did_not_complete_the_captcha_verification_properly');
     }
     $data = $this->_input->filter(array('username' => XenForo_Input::STRING, 'email' => XenForo_Input::STRING, 'timezone' => XenForo_Input::STRING, 'gender' => XenForo_Input::STRING, 'dob_day' => XenForo_Input::UINT, 'dob_month' => XenForo_Input::UINT, 'dob_year' => XenForo_Input::UINT));
     $passwords = $this->_input->filter(array('password' => XenForo_Input::STRING, 'password_confirm' => XenForo_Input::STRING));
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         $errors[] = 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);
     $writer->setPassword($passwords['password'], $passwords['password_confirm']);
     // if the email corresponds to an existing Gravatar, use it
     if ($options->gravatarEnable && XenForo_Model_Avatar::gravatarExists($data['email'])) {
         $writer->set('gravatar', $data['email']);
     }
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $writer->advanceRegistrationUserState();
     $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) {
                 $writer->error(new XenForo_Phrase('please_enter_valid_date_of_birth'), 'dob');
             } else {
                 if ($userAge < intval($options->get('registrationSetup', 'minimumAge'))) {
                     // TODO: set a cookie to prevent re-registration attempts
                     $errors[] = new XenForo_Phrase('sorry_you_too_young_to_create_an_account');
                 }
             }
         }
     }
     $errors = array_merge($errors, $writer->getErrors());
     if ($errors) {
         $fields = $data;
         $fields['tos'] = $this->_input->filterSingle('agree', XenForo_Input::UINT);
         return $this->_getRegisterFormResponse($fields, $errors);
     }
     $writer->save();
     $user = $writer->getMergedData();
     // log the ip of the user registering
     XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register');
     if ($user['user_state'] == 'email_confirm') {
         $this->_getUserConfirmationModel()->sendEmailConfirmation($user);
     }
     XenForo_Application::get('session')->changeUserId($user['user_id']);
     XenForo_Visitor::setup($user['user_id']);
     $viewParams = array('user' => $user);
     return $this->responseView('XenForo_ViewPublic_Register_Process', 'register_process', $viewParams, $this->_getRegistrationContainerParams());
 }
Esempio n. 12
0
 /**
  * Returns a Gravatar URL for the user
  *
  * @param array $user
  * @param string|integer $size (s,m,l)
  * @param string Override default (useful to use '404')
  */
 protected static function _getGravatarUrl(array $user, $size, $default = '')
 {
     $md5 = md5(strtolower(trim($user['gravatar'])));
     if ($default === '') {
         $default = '&d=' . urlencode(XenForo_Link::convertUriToAbsoluteUri(self::_getDefaultAvatarUrl($user, $size), true));
     } else {
         if (!empty($default)) {
             $default = '&d=' . urlencode($default);
         }
     }
     if (is_string($size)) {
         $size = XenForo_Model_Avatar::getSizeFromCode($size);
     }
     return (XenForo_Application::$secure ? 'https://secure' : 'http://www') . ".gravatar.com/avatar/{$md5}?s={$size}{$default}";
 }
Esempio n. 13
0
    protected function _importUser(array $user, array $options)
    {
        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        if ($this->_groupMap === null) {
            $this->_groupMap = $this->_importModel->getImportContentMap('userGroup');
        }
        if ($this->_userFieldMap === null) {
            $this->_userFieldMap = $this->_importModel->getImportContentMap('userField');
        }
        if ($this->_userActivationSetting === null) {
            $this->_userActivationSetting = $sDb->fetchOne('
				SELECT value
				FROM ' . $prefix . 'settings
				WHERE name = \'regtype\'
			');
        }
        $groups = preg_split('/,\\s*/', $user['additionalgroups'], -1, PREG_SPLIT_NO_EMPTY);
        $import = array('username' => $this->_convertToUtf8($user['username'], true), 'email' => $this->_convertToUtf8($user['email'], true), 'user_group_id' => $this->_mapLookUp($this->_groupMap, $user['usergroup'], XenForo_Model_User::$defaultRegisteredGroupId), 'secondary_group_ids' => $this->_mapLookUpList($this->_groupMap, $groups), 'authentication' => array('scheme_class' => 'XenForo_Authentication_MyBb', 'data' => array('hash' => $user['password'], 'salt' => $user['salt'])), 'last_activity' => $user['lastvisit'], 'register_date' => $user['regdate'], 'ip' => $user['regip'], 'homepage' => $this->_convertToUtf8($user['website'], true), 'message_count' => $user['postnum'], 'is_admin' => $user['admin_permissions'] ? 1 : 0, 'is_banned' => $user['ban_dateline'] ? 1 : 0, 'signature' => $this->_sanitizeBbCode($user['signature']), 'timezone' => $this->_importModel->resolveTimeZoneOffset($user['timezone'], $user['dstcorrection']), 'visible' => !$user['invisible'], 'content_show_signature' => $user['showsigs'], 'receive_admin_email' => $user['allownotices'], 'default_watch_state' => $user['subscriptionmethod'] == 2 ? 'watch_email' : ($user['subscriptionmethod'] == 1 ? 'watch_no_email' : ''), 'allow_send_personal_conversation' => $user['receivepms'] ? 'everyone' : 'none', 'email_on_conversation' => $user['pmnotify']);
        if ($user['usergroup'] == 5) {
            $import['user_state'] = $this->_userActivationSetting == 'admin' ? 'moderated' : 'email_confirm';
        } else {
            $import['user_state'] = 'valid';
        }
        if ($user['birthday']) {
            $parts = explode('-', $user['birthday']);
            if (count($parts) == 3) {
                $import['dob_day'] = trim($parts[0]);
                $import['dob_month'] = trim($parts[1]);
                $import['dob_year'] = trim($parts[2]);
            }
        }
        // try to give users without an avatar that have actually posted a gravatar
        if (!empty($options['gravatar'])) {
            // 1 = uploaded avatar
            if ($user['avatartype'] != 'uploaded' && $user['email'] && $user['lastpost'] && XenForo_Model_Avatar::gravatarExists($user['email'])) {
                $import['gravatar'] = $import['email'];
            }
        }
        $import['about'] = isset($user['fid2']) ? $this->_convertToUtf8($user['fid2'], true) : '';
        $import['location'] = isset($user['fid1']) ? $this->_convertToUtf8($user['fid1'], true) : '';
        if (!empty($user['fid3'])) {
            if ($user['fid3'] == 'Male') {
                $import['gender'] = 'male';
            } else {
                if ($user['fid3'] == 'Female') {
                    $import['gender'] = 'female';
                }
            }
        }
        // custom user fields
        $userFieldDefinitions = $this->_importModel->getUserFieldDefinitions();
        $identityMap = array('icq' => 'icq', 'aim' => 'aim', 'yahoo' => 'yahoo', 'msn' => 'msn');
        foreach ($identityMap as $identityType => $field) {
            if (isset($userFieldDefinitions[$identityType])) {
                $import[XenForo_Model_Import::USER_FIELD_KEY][$identityType] = $this->_convertToUtf8($user[$field], true);
            }
        }
        $userFieldLookups = $this->_session->getExtraData('userFieldLookups');
        foreach ($this->_userFieldMap as $oldFieldId => $newFieldId) {
            if (!isset($userFieldDefinitions[$newFieldId])) {
                continue;
            }
            $userFieldValue = '';
            if (isset($user["fid{$oldFieldId}"]) && $user["fid{$oldFieldId}"] !== '') {
                if (isset($userFieldLookups[$oldFieldId])) {
                    $fieldInfo = $userFieldLookups[$oldFieldId];
                    $userFieldValue = array();
                    foreach (preg_split('/\\r?\\n/', $user["fid{$oldFieldId}"], -1, PREG_SPLIT_NO_EMPTY) as $fieldChoiceId) {
                        if (isset($fieldInfo[$fieldChoiceId])) {
                            $userFieldValue[$fieldInfo[$fieldChoiceId]] = $fieldInfo[$fieldChoiceId];
                        }
                    }
                    $userFieldValue = array_unique($userFieldValue);
                } else {
                    // set the field value directly
                    $userFieldValue = $this->_convertToUtf8($user["fid{$oldFieldId}"], true);
                }
            }
            $import[XenForo_Model_Import::USER_FIELD_KEY][$newFieldId] = $userFieldValue;
        }
        if ($import['is_admin'] && $user['admin_permissions']) {
            $myBbAdminPerms = @unserialize($user['admin_permissions']);
            if (is_array($myBbAdminPerms)) {
                $aPerms = array();
                if (!empty($myBbAdminPerms['config']['settings'])) {
                    $aPerms[] = 'option';
                }
                if (!empty($myBbAdminPerms['config']['smilies'])) {
                    $aPerms[] = 'bbCodeSmilie';
                }
                if (!empty($myBbAdminPerms['config']['plugins'])) {
                    $aPerms[] = 'addOn';
                }
                if (!empty($myBbAdminPerms['forum']['management'])) {
                    $aPerms[] = 'node';
                }
                if (!empty($myBbAdminPerms['forum']['management'])) {
                    $aPerms[] = 'thread';
                }
                if (!empty($myBbAdminPerms['forum']['attachments'])) {
                    $aPerms[] = 'attachment';
                }
                if (!empty($myBbAdminPerms['forum']['announcements'])) {
                    $aPerms[] = 'notice';
                }
                if (!empty($myBbAdminPerms['user']['users'])) {
                    $aPerms[] = 'user';
                }
                if (!empty($myBbAdminPerms['user']['users'])) {
                    $aPerms[] = 'userField';
                }
                if (!empty($myBbAdminPerms['user']['users'])) {
                    $aPerms[] = 'trophy';
                }
                if (!empty($myBbAdminPerms['user']['users'])) {
                    $aPerms[] = 'warning';
                }
                if (!empty($myBbAdminPerms['user']['banning'])) {
                    $aPerms[] = 'ban';
                }
                if (!empty($myBbAdminPerms['user']['group'])) {
                    $aPerms[] = 'userGroup';
                }
                if (!empty($myBbAdminPerms['user']['users'])) {
                    $aPerms[] = 'userUpgrade';
                }
                if (!empty($myBbAdminPerms['style']['templates'])) {
                    $aPerms[] = 'style';
                }
                if (!empty($myBbAdminPerms['style']['templates'])) {
                    $aPerms[] = 'language';
                }
                if (!empty($myBbAdminPerms['tools']['tasks'])) {
                    $aPerms[] = 'cron';
                }
                if (!empty($myBbAdminPerms['tools']['cache'])) {
                    $aPerms[] = 'rebuildCache';
                }
                if (!empty($myBbAdminPerms['tools']['statistics'])) {
                    $aPerms[] = 'viewStatistics';
                }
                if (!empty($myBbAdminPerms['tools']['modlog'])) {
                    $aPerms[] = 'viewLogs';
                }
                if (!empty($myBbAdminPerms['forum']['management'])) {
                    $aPerms[] = 'import';
                }
                $aPerms[] = 'upgradeXenForo';
                $import['admin_permissions'] = $aPerms;
            }
        }
        $importedUserId = $this->_importModel->importUser($user['uid'], $import, $failedKey);
        if ($importedUserId) {
            if ($user['ban_dateline']) {
                $this->_importModel->importBan(array('user_id' => $importedUserId, 'ban_user_id' => 0, 'ban_date' => $user['ban_dateline'], 'end_date' => $user['ban_lifted'], 'user_reason' => $this->_convertToUtf8($user['ban_reason'], true)));
            }
        } else {
            if ($failedKey) {
                $this->_session->setExtraData('userFailed', $user['uid'], $failedKey);
            }
        }
        return $importedUserId;
    }
Esempio n. 14
0
 protected function _importUser(array $user, array $options)
 {
     if ($this->_groupMap === null) {
         $this->_groupMap = $this->_importModel->getImportContentMap('userGroup');
     }
     $user['options'] = intval($user['options']);
     $import = array('username' => $this->_convertToUtf8($user['username'], true), 'email' => $this->_convertToUtf8($user['email']), 'user_group_id' => $this->_mapLookUp($this->_groupMap, $user['usergroupid'], XenForo_Model_User::$defaultRegisteredGroupId), 'secondary_group_ids' => $this->_mapLookUpList($this->_groupMap, explode(',', $user['membergroupids'])), 'authentication' => array('scheme_class' => 'XenForo_Authentication_vBulletin', 'data' => array('hash' => $user['password'], 'salt' => $user['salt'])), 'homepage' => $this->_convertToUtf8($user['homepage']), 'last_activity' => $user['lastactivity'], 'register_date' => $user['joindate'], 'ip' => $user['ipaddress'], 'message_count' => $user['posts'], 'is_admin' => $user['is_admin'], 'is_banned' => $user['is_banned'], 'signature' => $this->_convertToUtf8($user['signature']), 'timezone' => $this->_importModel->resolveTimeZoneOffset($user['timezoneoffset'], $user['options'] & 64), 'content_show_signature' => $user['options'] & 1 ? 1 : 0, 'receive_admin_email' => $user['options'] & 16 ? 1 : 0);
     if ($user['customtitle']) {
         $import['custom_title'] = $this->_convertToUtf8($user['usertitle']);
         if ($user['customtitle'] == 2) {
             $import['custom_title'] = htmlspecialchars_decode($import['custom_title']);
             $import['custom_title'] = preg_replace('#<br\\s*/?>#i', ', ', $import['custom_title']);
             $import['custom_title'] = strip_tags($import['custom_title']);
         }
     }
     if (!($user['options'] & 2048)) {
         $import['allow_send_personal_conversation'] = 'none';
     } else {
         if ($user['options'] & 131072) {
             $import['allow_send_personal_conversation'] = 'followed';
         }
     }
     if (!($user['options'] & 8388608)) {
         $import['allow_post_profile'] = 'none';
     } else {
         if ($user['options'] & 16777216) {
             $import['allow_post_profile'] = 'followed';
         }
     }
     if ($user['birthday']) {
         $parts = explode('-', $user['birthday']);
         if (count($parts) == 3) {
             $import['dob_day'] = $parts[1];
             $import['dob_month'] = $parts[0];
             $import['dob_year'] = $parts[2];
         }
     }
     // try to give users without an avatar that have actually posted a gravatar
     if (!empty($options['gravatar'])) {
         if (!$user['has_custom_avatar'] && $user['email'] && $user['lastpost'] && XenForo_Model_Avatar::gravatarExists($user['email'])) {
             $import['gravatar'] = $import['email'];
         }
     }
     $import['about'] = '';
     if (isset($user['field1'])) {
         $import['about'] .= $this->_convertToUtf8($user['field1']) . "\n\n";
     }
     if (isset($user['field3'])) {
         $import['about'] .= $this->_convertToUtf8($user['field3']) . "\n\n";
     }
     $import['about'] = trim($import['about']);
     // TODO: potentially import additional custom fields as about
     if (isset($user['field2'])) {
         $import['location'] = $this->_convertToUtf8($user['field2']);
     }
     if (isset($user['field4'])) {
         $import['occupation'] = $this->_convertToUtf8($user['field4']);
     }
     switch ($user['usergroupid']) {
         case 3:
             $import['user_state'] = 'email_confirm';
             break;
         case 4:
             $import['user_state'] = 'moderated';
             break;
         default:
             $import['user_state'] = 'valid';
     }
     switch ($user['autosubscribe']) {
         case -1:
             $import['default_watch_state'] = '';
             break;
         case 0:
             $import['default_watch_state'] = 'watch_no_email';
             break;
         default:
             $import['default_watch_state'] = 'watch_email';
     }
     switch ($user['showbirthday']) {
         case 0:
             $import['show_dob_year'] = 0;
             $import['show_dob_date'] = 0;
             break;
         case 1:
             $import['show_dob_year'] = 1;
             $import['show_dob_date'] = 0;
             break;
         case 2:
             $import['show_dob_year'] = 1;
             $import['show_dob_date'] = 1;
             break;
         case 3:
             $import['show_dob_year'] = 0;
             $import['show_dob_date'] = 1;
             break;
     }
     $import['identities'] = array();
     if ($user['icq']) {
         $import['identities']['icq'] = $this->_convertToUtf8($user['icq']);
     }
     if ($user['aim']) {
         $import['identities']['aim'] = $this->_convertToUtf8($user['aim']);
     }
     if ($user['yahoo']) {
         $import['identities']['yahoo'] = $this->_convertToUtf8($user['yahoo']);
     }
     if ($user['msn']) {
         $import['identities']['msn'] = $this->_convertToUtf8($user['msn']);
     }
     if ($user['skype']) {
         $import['identities']['skype'] = $this->_convertToUtf8($user['skype']);
     }
     if ($user['is_admin'] && $user['admin_permissions']) {
         $user['admin_permissions'] = intval($user['admin_permissions']);
         $aPerms = array();
         if ($user['admin_permissions'] & 4) {
             $aPerms[] = 'option';
         }
         if ($user['admin_permissions'] & 8) {
             $aPerms[] = 'style';
         }
         if ($user['admin_permissions'] & 16) {
             $aPerms[] = 'language';
         }
         if ($user['admin_permissions'] & 32) {
             $aPerms[] = 'node';
         }
         if ($user['admin_permissions'] & 256) {
             $aPerms[] = 'user';
             $aPerms[] = 'ban';
             $aPerms[] = 'identityService';
             $aPerms[] = 'trophy';
             $aPerms[] = 'userUpgrade';
         }
         if ($user['admin_permissions'] & 512) {
             $aPerms[] = 'userGroup';
         }
         // actually, user permissions
         if ($user['admin_permissions'] & 4096) {
             $aPerms[] = 'bbCodeSmilie';
         }
         if ($user['admin_permissions'] & 8192) {
             $aPerms[] = 'cron';
         }
         if ($user['admin_permissions'] & 16384) {
             $aPerms[] = 'import';
             $aPerms[] = 'upgradeXenForo';
         }
         if ($user['admin_permissions'] & 65536) {
             $aPerms[] = 'addOn';
         }
         $import['admin_permissions'] = $aPerms;
     }
     $importedUserId = $this->_importModel->importUser($user['userid'], $import, $failedKey);
     if ($importedUserId) {
         if ($user['is_banned']) {
             $this->_importModel->importBan(array('user_id' => $importedUserId, 'ban_user_id' => $this->_importModel->mapUserId($user['ban_user_id'], 0), 'ban_date' => $user['ban_date'], 'end_date' => $user['ban_end_date'], 'user_reason' => $this->_convertToUtf8($user['ban_reason'])));
         }
         if ($user['is_super_moderator']) {
             $this->_session->setExtraData('superMods', $user['userid'], $importedUserId);
         }
         if ($user['buddylist']) {
             $buddyIds = array_slice(explode(' ', $user['buddylist']), 0, 1000);
             $buddyIds = $this->_importModel->getImportContentMap('user', $buddyIds);
             $this->_importModel->importFollowing($importedUserId, $buddyIds);
         }
     } else {
         if ($failedKey) {
             $this->_session->setExtraData('userFailed', $user['userid'], $failedKey);
         }
     }
     return $importedUserId;
 }
Esempio n. 15
0
 /**
  *
  * @param array $contact
  * @param array $user
  * @return array|boolean|null $user
  */
 public function pullContact(array $contact, $user = null)
 {
     $xenOptions = XenForo_Application::get('options');
     /* @var $userModel XenForo_Model_User */
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     if ($user === null) {
         $user = $userModel->getUserByContactId($contact['Id']);
     }
     if (!$user && !empty($contact['Email'])) {
         $user = $userModel->getUserByEmail($contact['Email'], array('join' => XenForo_Model_User::FETCH_USER_PROFILE));
         if ($user && !empty($user['infusionsoft_contact_id_th'])) {
             return;
         }
     }
     $lastUpdated = ThemeHouse_Infusionsoft_Helper_InfusionsoftApi::getDateAsTimestamp($contact['LastUpdated']);
     if ($user && !empty($user['infusionsoft_last_updated_th']) && $user['infusionsoft_last_updated_th'] == $lastUpdated) {
         return $user;
     }
     if (!$user) {
         if (empty($contact['Groups'])) {
             return false;
         } else {
             $groups = explode(',', $contact['Groups']);
             if (!array_intersect($groups, $xenOptions->th_infusionsoftApi_importUserTags)) {
                 return false;
             }
         }
     }
     /* @var $writer XenForo_DataWriter_User */
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $writer->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
     if ($user) {
         $writer->setExistingData($user);
     }
     $writer->set('infusionsoft_contact_id_th', $contact['Id']);
     $writer->set('infusionsoft_last_updated_th', $lastUpdated);
     if (!$user) {
         if ($xenOptions->registrationDefaults) {
             $writer->bulkSet($xenOptions->registrationDefaults, array('ignoreInvalidFields' => true));
         }
         $name = $this->getFullNameFromContact($contact);
         $input = array('user_group_id' => XenForo_Model_User::$defaultRegisteredGroupId, 'language_id' => XenForo_Visitor::getInstance()->get('language_id'), 'user_state' => 'valid', 'username' => $name);
         $i = 1;
         while ($userModel->getUserByName($input['username'])) {
             $input['username'] = $name . ' ' . $i;
             $i++;
         }
         $writer->bulkSet($input);
         $password = XenForo_Application::generateRandomString(8);
         $password = strtr($password, array('I' => 'i', 'l' => 'L', '0' => 'O', 'o' => 'O'));
         $password = trim($password, '_-');
         $writer->setPassword($password);
     }
     if (!empty($contact['Email'])) {
         $writer->set('email', $contact['Email']);
         if ($xenOptions->gravatarEnable && XenForo_Model_Avatar::gravatarExists($contact['Email'])) {
             $writer->set('gravatar', $contact['Email']);
         }
     } else {
         $writer->setOption(ThemeHouse_Infusionsoft_Extend_XenForo_DataWriter_User::OPTION_INFUSIONSOFT_API_IMPORT, true);
         $writer->set('email', '');
     }
     if (!empty($contact['Groups'])) {
         $writer->set('infusionsoft_contact_group_ids_th', $contact['Groups']);
     } else {
         $writer->set('infusionsoft_contact_group_ids_th', '');
     }
     $writer->save();
     $user = $writer->getMergedData();
     /* @var $promotionModel XenForo_Model_UserGroupPromotion */
     $promotionModel = $this->getModelFromCache('XenForo_Model_UserGroupPromotion');
     $promotionModel->updatePromotionsForUser($user);
     return $user;
 }