/**
  * @see	\wcf\data\AbstractDatabaseObjectAction::create()
  */
 public function create()
 {
     $bbCode = parent::create();
     // add bbcode to BBCodeSelect user group options
     $sql = "SELECT\toptionID\n\t\t\tFROM\twcf" . WCF_N . "_user_group_option\n\t\t\tWHERE\toptionType = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array('BBCodeSelect'));
     $optionIDs = array();
     while ($optionID = $statement->fetchColumn()) {
         $optionIDs[] = $optionID;
     }
     if (!empty($optionIDs)) {
         $conditionBuilder = new PreparedStatementConditionBuilder();
         $conditionBuilder->add("optionID IN (?)", array($optionIDs));
         $conditionBuilder->add("groupID IN (?)", array(UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE))));
         $conditionBuilder->add("optionValue <> ?", array('all'));
         $sql = "SELECT\t*\n\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\t" . $conditionBuilder;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditionBuilder->getParameters());
         $sql = "UPDATE\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\tSET\toptionValue = ?\n\t\t\t\tWHERE\toptionID = ?\n\t\t\t\t\tAND groupID = ?";
         $updateStatement = WCF::getDB()->prepareStatement($sql);
         WCF::getDB()->beginTransaction();
         while ($row = $statement->fetchArray()) {
             if (!empty($row['optionValue'])) {
                 $row['optionValue'] .= ',' . $bbCode->bbcodeTag;
             } else {
                 $row['optionValue'] = $bbCode->bbcodeTag;
             }
             $updateStatement->execute(array($row['optionValue'], $row['optionID'], $row['groupID']));
         }
         WCF::getDB()->commitTransaction();
         // clear user group option cache
         UserGroupEditor::resetCache();
     }
     return $bbCode;
 }
Exemple #2
0
 /**
  * Disables users.
  */
 public function disable()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     $action = new UserAction($this->objects, 'update', array('data' => array('activationCode' => UserRegistrationUtil::getActivationCode()), 'removeGroups' => UserGroup::getGroupIDsByType(array(UserGroup::USERS))));
     $action->executeAction();
     $action = new UserAction($this->objects, 'addToGroups', array('groups' => UserGroup::getGroupIDsByType(array(UserGroup::GUESTS)), 'deleteOldGroups' => false, 'addDefaultGroups' => false));
     $action->executeAction();
     $this->unmarkItems();
 }
Exemple #3
0
 /**
  * Returns an array with all the groups in which the actual user is a member.
  *
  * @return 	array 		$groupIDs
  */
 public function getGroupIDs()
 {
     if ($this->groupIDs === null) {
         if (!$this->userID) {
             // user is a guest, use default guest group
             $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::GUESTS, UserGroup::EVERYONE));
         } else {
             // load storage data
             UserStorageHandler::getInstance()->loadStorage(array($this->userID));
             // get group ids
             $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs');
             // cache does not exist or is outdated
             if ($data[$this->userID] === null) {
                 $this->groupIDs = array();
                 $sql = "SELECT\tgroupID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\tWHERE\tuserID = ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute(array($this->userID));
                 while ($row = $statement->fetchArray()) {
                     $this->groupIDs[] = $row['groupID'];
                 }
                 // update storage data
                 UserStorageHandler::getInstance()->update($this->userID, 'groupIDs', serialize($this->groupIDs), 1);
             } else {
                 $this->groupIDs = unserialize($data[$this->userID]);
             }
         }
     }
     return $this->groupIDs;
 }
Exemple #4
0
 /**
  * Adds a user to the groups he should be in.
  * 
  * @param	array		$groups
  * @param	boolean		$deleteOldGroups
  * @param	boolean		$addDefaultGroups
  */
 public function addToGroups(array $groupIDs, $deleteOldGroups = true, $addDefaultGroups = true)
 {
     // add default groups
     if ($addDefaultGroups) {
         $groupIDs = array_merge($groupIDs, UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::USERS)));
         $groupIDs = array_unique($groupIDs);
     }
     // remove old groups
     if ($deleteOldGroups) {
         $sql = "DELETE FROM\twcf" . WCF_N . "_user_to_group\n\t\t\t\tWHERE\t\tuserID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->userID));
     }
     // insert new groups
     if (!empty($groupIDs)) {
         $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\t\t(userID, groupID)\n\t\t\t\tVALUES\t\t\t(?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($groupIDs as $groupID) {
             $statement->execute(array($this->userID, $groupID));
         }
     }
 }
 /**
  * @see \wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     // get options
     $saveOptions = $this->optionHandler->save();
     $registerVia3rdParty = true;
     $avatarURL = '';
     if (isset($this->ttid_profile['avatar_url']) && !empty($this->ttid_profile['avatar_url'])) {
         $avatarURL = $this->ttid_profile['avatar_url'];
     }
     $this->additionalFields['languageID'] = $this->languageID;
     if (LOG_IP_ADDRESS) {
         $this->additionalFields['registrationIpAddress'] = WCF::getSession()->ipAddress;
     }
     // generate activation code
     $addDefaultGroups = true;
     if ($this->verified !== true && REGISTER_ACTIVATION_METHOD != 0 || $this->verified === true && REGISTER_ACTIVATION_METHOD == 2 && !WBB_TAPATALK_REG_AUTO_APPROVAL) {
         $activationCode = UserRegistrationUtil::getActivationCode();
         $this->additionalFields['activationCode'] = $activationCode;
         $addDefaultGroups = false;
         $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS));
     }
     // check gravatar support
     if (MODULE_GRAVATAR && Gravatar::test($this->email)) {
         $this->additionalFields['enableGravatar'] = 1;
     }
     // create user
     $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions, 'addDefaultGroups' => $addDefaultGroups);
     $this->objectAction = new UserAction(array(), 'create', $data);
     $result = $this->objectAction->executeAction();
     $user = $result['returnValues'];
     $userEditor = new UserEditor($user);
     // set avatar if provided
     if (!empty($avatarURL)) {
         $userAvatarAction = new UserAvatarAction(array(), 'fetchRemoteAvatar', array('url' => $avatarURL, 'userEditor' => $userEditor));
         $userAvatarAction->executeAction();
     }
     // update session
     WCF::getSession()->changeUser($user);
     // activation management
     if (REGISTER_ACTIVATION_METHOD == 0) {
         $this->message = 'wcf.user.register.success';
     } else {
         if (REGISTER_ACTIVATION_METHOD == 1) {
             // registering via 3rdParty leads to instant activation
             if ($registerVia3rdParty && $this->verified) {
                 $this->message = 'wcf.user.register.success';
             } else {
                 $mail = new Mail(array($this->username => $this->email), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail', array('user' => $user)));
                 $mail->send();
                 $this->message = 'wcf.user.register.needActivation';
             }
         } else {
             if (REGISTER_ACTIVATION_METHOD == 2 && (!$this->verified || $this->verified && !WBB_TAPATALK_REG_AUTO_APPROVAL)) {
                 $this->message = 'wcf.user.register.awaitActivation';
             }
         }
     }
     // notify admin
     if (REGISTER_ADMIN_NOTIFICATION) {
         // get default language
         $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID());
         // send mail
         $mail = new Mail(MAIL_ADMIN_ADDRESS, $language->getDynamicVariable('wcf.user.register.notification.mail.subject'), $language->getDynamicVariable('wcf.user.register.notification.mail', array('user' => $user)));
         $mail->setLanguage($language);
         $mail->send();
     }
     if ($this->captchaObjectType) {
         $this->captchaObjectType->getProcessor()->reset();
     }
     if (WCF::getSession()->getVar('noRegistrationCaptcha')) {
         WCF::getSession()->unregister('noRegistrationCaptcha');
     }
     // login user
     UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($user, $this->username, $this->password);
     WCF::getSession()->unregister('registrationStartTime');
     $this->saved();
 }
Exemple #6
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     // get options
     $saveOptions = $this->optionHandler->save();
     $registerVia3rdParty = false;
     $avatarURL = '';
     if ($this->isExternalAuthentication) {
         switch (WCF::getSession()->getVar('__3rdPartyProvider')) {
             case 'github':
                 // GitHub
                 if (WCF::getSession()->getVar('__githubData')) {
                     $githubData = WCF::getSession()->getVar('__githubData');
                     $this->additionalFields['authData'] = 'github:' . WCF::getSession()->getVar('__githubToken');
                     WCF::getSession()->unregister('__githubData');
                     WCF::getSession()->unregister('__githubToken');
                     if (WCF::getSession()->getVar('__email') && WCF::getSession()->getVar('__email') == $this->email) {
                         $registerVia3rdParty = true;
                     }
                     if (isset($githubData['bio']) && User::getUserOptionID('aboutMe') !== null) {
                         $saveOptions[User::getUserOptionID('aboutMe')] = $githubData['bio'];
                     }
                     if (isset($githubData['location']) && User::getUserOptionID('location') !== null) {
                         $saveOptions[User::getUserOptionID('location')] = $githubData['location'];
                     }
                 }
                 break;
             case 'twitter':
                 // Twitter
                 if (WCF::getSession()->getVar('__twitterData')) {
                     $twitterData = WCF::getSession()->getVar('__twitterData');
                     $this->additionalFields['authData'] = 'twitter:' . $twitterData['user_id'];
                     WCF::getSession()->unregister('__twitterData');
                     if (isset($twitterData['description']) && User::getUserOptionID('aboutMe') !== null) {
                         $saveOptions[User::getUserOptionID('aboutMe')] = $twitterData['description'];
                     }
                     if (isset($twitterData['location']) && User::getUserOptionID('location') !== null) {
                         $saveOptions[User::getUserOptionID('location')] = $twitterData['location'];
                     }
                 }
                 break;
             case 'facebook':
                 // Facebook
                 if (WCF::getSession()->getVar('__facebookData')) {
                     $facebookData = WCF::getSession()->getVar('__facebookData');
                     $this->additionalFields['authData'] = 'facebook:' . $facebookData['id'];
                     WCF::getSession()->unregister('__facebookData');
                     if (isset($facebookData['email']) && $facebookData['email'] == $this->email) {
                         $registerVia3rdParty = true;
                     }
                     if (isset($facebookData['gender']) && User::getUserOptionID('gender') !== null) {
                         $saveOptions[User::getUserOptionID('gender')] = $facebookData['gender'] == 'male' ? UserProfile::GENDER_MALE : UserProfile::GENDER_FEMALE;
                     }
                     if (isset($facebookData['birthday']) && User::getUserOptionID('birthday') !== null) {
                         list($month, $day, $year) = explode('/', $facebookData['birthday']);
                         $saveOptions[User::getUserOptionID('birthday')] = $year . '-' . $month . '-' . $day;
                     }
                     if (isset($facebookData['bio']) && User::getUserOptionID('bio') !== null) {
                         $saveOptions[User::getUserOptionID('aboutMe')] = $facebookData['bio'];
                     }
                     if (isset($facebookData['location']) && User::getUserOptionID('location') !== null) {
                         $saveOptions[User::getUserOptionID('location')] = $facebookData['location']['name'];
                     }
                     if (isset($facebookData['website']) && User::getUserOptionID('website') !== null) {
                         $urls = preg_split('/[\\s,;]/', $facebookData['website'], -1, PREG_SPLIT_NO_EMPTY);
                         if (!empty($urls)) {
                             if (!Regex::compile('^https?://')->match($urls[0])) {
                                 $urls[0] = 'http://' . $urls[0];
                             }
                             $saveOptions[User::getUserOptionID('homepage')] = $urls[0];
                         }
                     }
                     // avatar
                     if (isset($facebookData['picture']) && !$facebookData['picture']['data']['is_silhouette']) {
                         $avatarURL = $facebookData['picture']['data']['url'];
                     }
                 }
                 break;
             case 'google':
                 // Google Plus
                 if (WCF::getSession()->getVar('__googleData')) {
                     $googleData = WCF::getSession()->getVar('__googleData');
                     $this->additionalFields['authData'] = 'google:' . $googleData['id'];
                     WCF::getSession()->unregister('__googleData');
                     if (isset($googleData['emails'][0]['value']) && $googleData['emails'][0]['value'] == $this->email) {
                         $registerVia3rdParty = true;
                     }
                     if (isset($googleData['gender']) && User::getUserOptionID('gender') !== null) {
                         switch ($googleData['gender']) {
                             case 'male':
                                 $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_MALE;
                                 break;
                             case 'female':
                                 $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_FEMALE;
                                 break;
                         }
                     }
                     if (isset($googleData['birthday']) && User::getUserOptionID('birthday') !== null) {
                         $saveOptions[User::getUserOptionID('birthday')] = $googleData['birthday'];
                     }
                     if (isset($googleData['placesLived']) && User::getUserOptionID('location') !== null) {
                         // save primary location
                         $saveOptions[User::getUserOptionID('location')] = current(array_map(function ($element) {
                             return $element['value'];
                         }, array_filter($googleData['placesLived'], function ($element) {
                             return isset($element['primary']) && $element['primary'];
                         })));
                     }
                     // avatar
                     if (isset($googleData['image']['url'])) {
                         $avatarURL = $googleData['image']['url'];
                     }
                 }
                 break;
         }
         // create fake password
         $this->password = StringUtil::getRandomID();
     }
     $this->additionalFields['languageID'] = $this->languageID;
     if (LOG_IP_ADDRESS) {
         $this->additionalFields['registrationIpAddress'] = WCF::getSession()->ipAddress;
     }
     // generate activation code
     $addDefaultGroups = true;
     if (REGISTER_ACTIVATION_METHOD == 1 && !$registerVia3rdParty || REGISTER_ACTIVATION_METHOD == 2) {
         $activationCode = UserRegistrationUtil::getActivationCode();
         $this->additionalFields['activationCode'] = $activationCode;
         $addDefaultGroups = false;
         $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS));
     }
     // check gravatar support
     if (MODULE_GRAVATAR && Gravatar::test($this->email)) {
         $this->additionalFields['enableGravatar'] = 1;
     }
     // create user
     $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions, 'addDefaultGroups' => $addDefaultGroups);
     $this->objectAction = new UserAction(array(), 'create', $data);
     $result = $this->objectAction->executeAction();
     $user = $result['returnValues'];
     $userEditor = new UserEditor($user);
     // update session
     WCF::getSession()->changeUser($user);
     // set avatar if provided
     if (!empty($avatarURL)) {
         $userAvatarAction = new UserAvatarAction(array(), 'fetchRemoteAvatar', array('url' => $avatarURL, 'userEditor' => $userEditor));
         $userAvatarAction->executeAction();
     }
     // activation management
     if (REGISTER_ACTIVATION_METHOD == 0) {
         $this->message = 'wcf.user.register.success';
     } else {
         if (REGISTER_ACTIVATION_METHOD == 1) {
             // registering via 3rdParty leads to instant activation
             if ($registerVia3rdParty) {
                 $this->message = 'wcf.user.register.success';
             } else {
                 $mail = new Mail(array($this->username => $this->email), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail', array('user' => $user)));
                 $mail->send();
                 $this->message = 'wcf.user.register.needActivation';
             }
         } else {
             if (REGISTER_ACTIVATION_METHOD == 2) {
                 $this->message = 'wcf.user.register.awaitActivation';
             }
         }
     }
     // notify admin
     if (REGISTER_ADMIN_NOTIFICATION) {
         // get default language
         $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID());
         // send mail
         $mail = new Mail(MAIL_ADMIN_ADDRESS, $language->getDynamicVariable('wcf.user.register.notification.mail.subject'), $language->getDynamicVariable('wcf.user.register.notification.mail', array('user' => $user)));
         $mail->setLanguage($language);
         $mail->send();
     }
     if ($this->captchaObjectType) {
         $this->captchaObjectType->getProcessor()->reset();
     }
     if (WCF::getSession()->getVar('noRegistrationCaptcha')) {
         WCF::getSession()->unregister('noRegistrationCaptcha');
     }
     // login user
     UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($user, $this->username, $this->password);
     WCF::getSession()->unregister('registrationRandomFieldNames');
     WCF::getSession()->unregister('registrationStartTime');
     $this->saved();
     // forward to index page
     HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->getDynamicVariable($this->message, array('user' => $user)), 15);
     exit;
 }
 /**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     // whether to perform a merge
     $performMerge = false;
     // fetch user with same username
     $conflictingUser = User::getUserByUsername($data['username']);
     switch (ImportHandler::getInstance()->getUserMergeMode()) {
         case self::MERGE_MODE_USERNAME_OR_EMAIL:
             // merge target will be the conflicting user
             $targetUser = $conflictingUser;
             // check whether user exists
             if ($targetUser->userID) {
                 $performMerge = true;
                 break;
             }
         case self::MERGE_MODE_EMAIL:
             // fetch merge target
             $targetUser = User::getUserByEmail($data['email']);
             // if it exists: perform a merge
             if ($targetUser->userID) {
                 $performMerge = true;
             }
             break;
     }
     // merge should be performed
     if ($performMerge) {
         ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user', $oldID, $targetUser->userID);
         return 0;
     }
     // a conflict arose, but no merge was performed, resolve
     if ($conflictingUser->userID) {
         // rename user
         $data['username'] = self::resolveDuplicate($data['username']);
     }
     // check existing user id
     if (is_numeric($oldID)) {
         $user = new User($oldID);
         if (!$user->userID) {
             $data['userID'] = $oldID;
         }
     }
     // handle user options
     $userOptions = array();
     if (isset($additionalData['options'])) {
         foreach ($additionalData['options'] as $optionName => $optionValue) {
             if (is_int($optionName)) {
                 $optionID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.option', $optionName);
             } else {
                 $optionID = User::getUserOptionID($optionName);
             }
             if ($optionID) {
                 $userOptions[$optionID] = $optionValue;
             }
         }
         // fix option values
         foreach ($userOptions as $optionID => &$optionValue) {
             switch ($this->userOptions[$optionID]->optionType) {
                 case 'boolean':
                     if ($optionValue) {
                         $optionValue = 1;
                     } else {
                         $optionValue = 0;
                     }
                     break;
                 case 'integer':
                     $optionValue = intval($optionValue);
                     if ($optionValue > 2147483647) {
                         $optionValue = 2147483647;
                     }
                     break;
                 case 'float':
                     $optionValue = floatval($optionValue);
                     break;
                 case 'textarea':
                     if (strlen($optionValue) > 16777215) {
                         $optionValue = substr($optionValue, 0, 16777215);
                     }
                     break;
                 case 'birthday':
                 case 'date':
                     if (!preg_match('/^\\d{4}\\-\\d{2}\\-\\d{2}$/', $optionValue)) {
                         $optionValue = '0000-00-00';
                     }
                     break;
                 default:
                     if (strlen($optionValue) > 65535) {
                         $optionValue = substr($optionValue, 0, 65535);
                     }
             }
         }
     }
     $languageIDs = array();
     if (isset($additionalData['languages'])) {
         foreach ($additionalData['languages'] as $languageCode) {
             $language = LanguageFactory::getInstance()->getLanguageByCode($languageCode);
             if ($language !== null) {
                 $languageIDs[] = $language->languageID;
             }
         }
     }
     if (empty($languageIDs)) {
         $languageIDs[] = LanguageFactory::getInstance()->getDefaultLanguageID();
     }
     // assign an interface language
     $data['languageID'] = reset($languageIDs);
     // create user
     $user = UserEditor::create($data);
     $userEditor = new UserEditor($user);
     // updates user options
     $userEditor->updateUserOptions($userOptions);
     // save user groups
     $groupIDs = array();
     if (isset($additionalData['groupIDs'])) {
         foreach ($additionalData['groupIDs'] as $oldGroupID) {
             $newGroupID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.group', $oldGroupID);
             if ($newGroupID) {
                 $groupIDs[] = $newGroupID;
             }
         }
     }
     if (!$user->activationCode) {
         $defaultGroupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::USERS));
     } else {
         $defaultGroupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS));
     }
     $groupIDs = array_merge($groupIDs, $defaultGroupIDs);
     $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\t(userID, groupID)\n\t\t\tVALUES\t\t\t(?, ?)";
     $statement = WCF::getDB()->prepareStatement($sql);
     foreach ($groupIDs as $groupID) {
         $statement->execute(array($user->userID, $groupID));
     }
     // save languages
     $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_to_language\n\t\t\t\t\t\t(userID, languageID)\n\t\t\tVALUES\t\t\t(?, ?)";
     $statement = WCF::getDB()->prepareStatement($sql);
     foreach ($languageIDs as $languageID) {
         $statement->execute(array($user->userID, $languageID));
     }
     // save default user events
     $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_notification_event_to_user\n\t\t\t\t\t\t(userID, eventID)\n\t\t\tVALUES\t\t\t(?, ?)";
     $statement = WCF::getDB()->prepareStatement($sql);
     foreach ($this->eventIDs as $eventID) {
         $statement->execute(array($user->userID, $eventID));
     }
     // save mapping
     ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user', $oldID, $user->userID);
     return $user->userID;
 }