コード例 #1
0
 /**
  * @see	\wcf\system\option\ISearchableConditionUserOption::checkUser()
  */
 public function checkUser(User $user, Option $option, $value)
 {
     if (!$value) {
         return false;
     }
     return $user->getUserOption($option->optionName);
 }
コード例 #2
0
 /**
  * @see	\wcf\system\condition\IUserCondition::checkUser()
  */
 public function checkUser(Condition $condition, User $user)
 {
     $groupIDs = $user->getGroupIDs();
     if (!empty($condition->conditionData['groupIDs']) && count(array_diff($condition->conditionData['groupIDs'], $groupIDs))) {
         return false;
     }
     if (!empty($condition->conditionData['notGroupIDs']) && count(array_intersect($condition->conditionData['notGroupIDs'], $groupIDs))) {
         return false;
     }
     return true;
 }
コード例 #3
0
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->username) && empty($this->email)) {
         throw new UserInputException('username');
     }
     if (!empty($this->username)) {
         $this->user = User::getUserByUsername($this->username);
         if (!$this->user->userID) {
             throw new UserInputException('username', 'notFound');
         }
     } else {
         $this->user = User::getUserByEmail($this->email);
         if (!$this->user->userID) {
             throw new UserInputException('email', 'notFound');
         }
     }
     // check if using 3rd party @author dtdesign
     if ($this->user->authData) {
         throw new UserInputException('username', '3rdParty');
     }
     // check whether a lost password request was sent in the last 24 hours
     if ($this->user->lastLostPasswordRequestTime && TIME_NOW - 86400 < $this->user->lastLostPasswordRequestTime) {
         throw new NamedUserException(WCF::getLanguage()->getDynamicVariable('wcf.user.lostPassword.error.tooManyRequests', array('hours' => ceil(($this->user->lastLostPasswordRequestTime - (TIME_NOW - 86400)) / 3600))));
     }
 }
コード例 #4
0
ファイル: ACLHandler.class.php プロジェクト: nick-strohm/WCF
 /**
  * Assignes the acl values to the template.
  * 
  * @param	integer		$objectTypeID
  */
 public function assignVariables($objectTypeID)
 {
     if (WCF::getTPL()->get('aclValues') === null) {
         WCF::getTPL()->assign('aclValues', array());
     }
     if (!$this->assignVariablesDisabled && isset($_POST['aclValues'])) {
         $values = $_POST['aclValues'];
         $data = $this->getPermissions($objectTypeID, array(), null, true);
         foreach ($values as $type => $optionData) {
             if ($type === 'user') {
                 $users = User::getUsers(array_keys($optionData));
             }
             $values[$type] = array('label' => array(), 'option' => array());
             foreach ($optionData as $typeID => $optionValues) {
                 foreach ($optionValues as $optionID => $optionValue) {
                     if (!isset($data['options'][$optionID])) {
                         unset($optionValues[$optionID]);
                     }
                 }
                 if (empty($optionValues)) {
                     continue;
                 }
                 $values[$type]['option'][$typeID] = $optionValues;
                 if ($type === 'group') {
                     $values[$type]['label'][$typeID] = UserGroup::getGroupByID($typeID)->getName();
                 } else {
                     $values[$type]['label'][$typeID] = $users[$typeID]->username;
                 }
             }
         }
         $values['options'] = $data['options'];
         $values['categories'] = $data['categories'];
         WCF::getTPL()->append('aclValues', array($objectTypeID => $values));
     }
 }
コード例 #5
0
 /**
  * Validates the password.
  */
 public function validatePassword()
 {
     if (empty($this->password)) {
         throw new UserInputException('password');
     }
     // check password
     if (!$this->user->checkPassword($this->password)) {
         throw new UserInputException('password', 'false');
     }
 }
コード例 #6
0
 /**
  * @see	\wcf\form\IForm::readFormParameters()
  */
 public function readFormParameters()
 {
     parent::readFormParameters();
     if (isset($_POST['username'])) {
         $this->username = StringUtil::trim($_POST['username']);
         $this->user = User::getUserByUsername($this->username);
     }
     if (isset($_POST['activationCode'])) {
         $this->activationCode = intval($_POST['activationCode']);
     }
 }
コード例 #7
0
 /**
  * Validates the username.
  */
 public function validateUsername()
 {
     if (empty($this->username)) {
         throw new UserInputException('username');
     }
     $this->user = User::getUserByUsername($this->username);
     if (!$this->user->userID) {
         throw new UserInputException('username', 'notFound');
     }
     if ($this->user->reactivationCode == 0) {
         throw new UserInputException('username', 'alreadyEnabled');
     }
 }
 /**
  * Handles the saved event.
  *
  * @param array $parameter
  */
 protected function saved(array $parameter)
 {
     // get message, check by difference is quickreply or postadd
     $message = $parameter == null ? $this->eventObj->text : $parameter['message']->message;
     //if (!\wcf\system\Regex::compile('(^Butler.*$)')->match($message, true)) return;
     // get cached questions from cache, filter it by array functions, easier then foreach
     $questions = \wbb\data\post\butler\question\QuestionCache::getInstance()->getQuestions();
     $questions = array_filter(array_map(function ($question) use($message) {
         if (!\wcf\system\Regex::compile(sprintf('(^%s.*$)', empty($question->prefixUsername) ? 'Butler' : $question->prefixUsername))->match($message, true)) {
             return false;
         } else {
             return $question->matches($message);
         }
     }, $questions), function ($value) {
         if ($value) {
             return $value;
         }
     });
     // check if a value is given, otherwise abort continue of function
     if ($questions == null) {
         return;
     } else {
         $question = \wbb\data\post\butler\question\QuestionCache::getInstance()->getQuestionByID(array_rand($questions, 1));
     }
     // get cached answers from cache, try to get only assigned answers
     $answers = \wbb\data\post\butler\answer\AnswerCache::getInstance()->getAnswers();
     $answers = $answers[$question->questionID];
     // check if a value is given and declare variable on success, otherwise abort function
     if ($answers == null) {
         return;
     } else {
         $answer = $answers[array_rand($answers, 1)];
     }
     $threadID = 0;
     if ($parameter == null) {
         $threadActionObject = $this->eventObj->objectAction->getReturnValues();
         $threadID = $threadActionObject['returnValues']->threadID;
     } else {
         $threadID = $this->eventObj->getContainer()->threadID;
     }
     $author = null;
     if ($question->prefixUserID > 0) {
         $author = \wcf\data\user\User::getUsers(array($question->prefixUserID));
         if (count($author) == 1) {
             $author = array_shift($author);
         }
     }
     $postData = array('threadID' => $threadID, 'userID' => $question->prefixUserID == 0 ? null : $question->prefixUserID, 'username' => $author == null ? empty($question->prefixUsername) ? 'Butler' : $question->prefixUsername : $author->username, 'message' => $answer->getFormattedMessage(), 'time' => TIME_NOW, 'enableSmilies' => $answer->enableSmilies, 'enableHtml' => $answer->enableHtml, 'enableBBCodes' => $answer->enableBBCodes, 'showSignature' => 0);
     $objectAction = new \wbb\data\post\PostAction(array(), 'create', array('data' => $postData));
     $objectAction->executeAction();
 }
コード例 #9
0
 /**
  * @see	\cms\system\content\type\IContentType::validate()
  */
 public function validate($data)
 {
     if (!isset($data['name']) || $data['name'] == '') {
         throw new UserInputException('data[name]');
     }
     $userProfile = User::getUserByUsername($data['name']);
     if (!$userProfile) {
         throw new UserInputException('data[name]', 'notValid');
     }
     // save user id instead of username
     $contentData =& RequestHandler::getInstance()->getActiveRequest()->getRequestObject()->contentData;
     $contentData['userID'] = $userProfile->userID;
     unset($contentData['name']);
 }
コード例 #10
0
 /**
  * Gets users online stats.
  */
 public function readStats()
 {
     $conditionBuilder = clone $this->getConditionBuilder();
     $conditionBuilder->add('session.spiderID IS NULL');
     $sql = "SELECT\t\tuser_option_value.userOption" . User::getUserOptionID('canViewOnlineStatus') . " AS canViewOnlineStatus, session.userID\n\t\t\tFROM\t\twcf" . WCF_N . "_session session\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value user_option_value\n\t\t\tON\t\t(user_option_value.userID = session.userID)\n\t\t\t" . $conditionBuilder;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditionBuilder->getParameters());
     while ($row = $statement->fetchArray()) {
         $this->stats['total']++;
         if ($row['userID']) {
             $this->stats['members']++;
             if ($row['canViewOnlineStatus'] && !self::isVisible($row['userID'], $row['canViewOnlineStatus'])) {
                 $this->stats['invisible']++;
             }
         } else {
             $this->stats['guests']++;
         }
     }
 }
コード例 #11
0
 /**
  * Loads language ids for active user.
  */
 protected function loadLanguageIDs()
 {
     if ($this->languageIDs !== null) {
         return;
     }
     $this->languageIDs = array();
     if (!$this->user->userID) {
         return;
     }
     // work-around for setup process (package wcf does not exist yet)
     if (!PACKAGE_ID) {
         $sql = "SELECT\tlanguageID\n\t\t\t\tFROM\twcf" . WCF_N . "_user_to_language\n\t\t\t\tWHERE\tuserID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->user->userID));
         while ($row = $statement->fetchArray()) {
             $this->languageIDs[] = $row['languageID'];
         }
     } else {
         $this->languageIDs = $this->user->getLanguageIDs();
     }
 }
コード例 #12
0
 /**
  * @see	\wcf\system\cache\builder\AbstractCacheBuilder::rebuild()
  */
 protected function rebuild(array $parameters)
 {
     $userOptionID = User::getUserOptionID('birthday');
     if ($userOptionID === null) {
         // birthday profile field missing; skip
         return array();
     }
     $data = array();
     $birthday = 'userOption' . $userOptionID;
     $sql = "SELECT\tuserID, " . $birthday . "\n\t\t\tFROM\twcf" . WCF_N . "_user_option_value\n\t\t\tWHERE\t" . $birthday . " LIKE ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array('%-' . ($parameters['month'] < 10 ? '0' : '') . $parameters['month'] . '-%'));
     while ($row = $statement->fetchArray()) {
         list($year, $month, $day) = explode('-', $row[$birthday]);
         if (!isset($data[$month . '-' . $day])) {
             $data[$month . '-' . $day] = array();
         }
         $data[$month . '-' . $day][] = $row['userID'];
     }
     return $data;
 }
コード例 #13
0
 /**
  * @see	\wcf\system\faker\IFaker::fake()
  */
 public function fake()
 {
     $username = $tmpName = $this->generator->userName;
     $username = str_replace(',', '', $username);
     while (!\wcf\util\UserUtil::isAvailableUsername($tmpName)) {
         $tmpName = $username . $this->generator->randomNumber(4);
     }
     $username = $tmpName;
     $password = $username;
     $email = $username . '@' . $this->generator->safeEmailDomain;
     // shouldn't happen
     if (!\wcf\util\UserUtil::isValidEmail($email)) {
         $email = $this->generator->safeEmail;
     }
     while (!\wcf\util\UserUtil::isAvailableEmail($email)) {
         $email = $this->generator->safeEmail;
     }
     $registrationDate = $this->generator->dateTimeBetween('2000-01-01 GMT', 'now')->getTimestamp();
     $lastActivityTime = $this->generator->optional($weight = 0.7)->numberBetween($registrationDate, TIME_NOW);
     $parameters = array('data' => array('languageID' => $this->language->languageID, 'username' => $username, 'email' => $email, 'password' => $password, 'registrationDate' => $registrationDate, 'lastActivityTime' => $lastActivityTime === null ? 0 : $lastActivityTime));
     if (isset($this->parameters['groupIDs'])) {
         $parameters['groups'] = $this->parameters['groupIDs'];
     }
     // handle old name
     if (isset($this->parameters['userRandomOldUsername']) && $this->parameters['userRandomOldUsername']) {
         // 2 percent chance
         if ($this->generator->boolean(2)) {
             $parameters['data']['oldUsername'] = $this->generator->userName;
         }
     }
     // handle signature
     if (isset($this->parameters['userRandomSignature']) && $this->parameters['userRandomSignature']) {
         $parameters['data']['signature'] = $this->generator->realText($this->generator->numberBetween(10, 500));
     }
     // handle options
     $options = array();
     // handle gender
     if (isset($this->parameters['userGender'])) {
         switch ($this->parameters['userGender']) {
             case 0:
             case 1:
             case 2:
                 $options[User::getUserOptionID('gender')] = $this->parameters['userGender'];
                 break;
             default:
                 $options[User::getUserOptionID('gender')] = $this->generator->numberBetween(0, 2);
                 break;
         }
     }
     // handle aboutMe
     if (isset($this->parameters['userRandomAboutMe']) && $this->parameters['userRandomAboutMe']) {
         $options[User::getUserOptionID('aboutMe')] = $this->generator->realText($this->generator->numberBetween(50, 1500));
     }
     // handle birthday
     if (isset($this->parameters['userRandomBirthday']) && $this->parameters['userRandomBirthday']) {
         $options[User::getUserOptionID('birthday')] = $this->generator->dateTimeBetween("-90 years", "-14 years")->format('Y-m-d');
     }
     // handle location
     if (isset($this->parameters['userRandomLocation']) && $this->parameters['userRandomLocation']) {
         $options[User::getUserOptionID('location')] = $this->generator->address;
     }
     // handle homepage
     if (isset($this->parameters['userRandomHomepage']) && $this->parameters['userRandomHomepage']) {
         $options[User::getUserOptionID('homepage')] = $this->generator->url;
     }
     if (!empty($options)) {
         $parameters['options'] = $options;
     }
     $objectAction = new \wcf\data\user\UserAction(array(), 'create', $parameters);
     $objectAction->executeAction();
 }
コード例 #14
0
 public function switchContext()
 {
     $userAction = new UserAction(array(WCF::getUser()), 'update', array('options' => array(User::getUserOptionID('recentActivitiesFilterByFollowing') => WCF::getUser()->recentActivitiesFilterByFollowing ? 0 : 1)));
     $userAction->executeAction();
 }
コード例 #15
0
 /**
  * @see	\wcf\system\option\ISearchableConditionUserOption::checkUser()
  */
 public function checkUser(User $user, Option $option, $value)
 {
     $value = StringUtil::trim($value);
     if ($value == '') {
         return $user->getUserOption($option->optionName) == '';
     } else {
         return mb_stripos($user->getUserOption($option->optionName), $value) !== false;
     }
 }
コード例 #16
0
 /**
  * @see wcf\system\user\authentication\DefaultUserAuthentication::getUserByLogin()
  */
 protected function getUserByLogin($login)
 {
     return User::getUserByEmail($login);
 }
コード例 #17
0
ファイル: MailWorker.class.php プロジェクト: nick-strohm/WCF
 /**
  * Sends the mail to given user.
  * 
  * @param	\wcf\data\user\User	$user
  */
 protected function sendMail(User $user)
 {
     try {
         $mail = new Mail(array($user->username => $user->email), $this->mailData['subject'], str_replace('{$username}', $user->username, $this->mailData['text']), $this->mailData['from']);
         if ($this->mailData['enableHTML']) {
             $mail->setContentType('text/html');
         }
         $mail->setLanguage($user->getLanguage());
         $mail->send();
     } catch (SystemException $e) {
         // ignore errors
     }
 }
コード例 #18
0
 /**
  * @see	\wcf\system\option\ISearchableConditionUserOption::checkUser()
  */
 public function checkUser(User $user, Option $option, $value)
 {
     if (!is_array($value) || empty($value)) {
         return false;
     }
     $optionValues = explode('\\n', $user->getUserOption($option->optionName));
     return count(array_diff($optionValues, $value)) > 0;
 }
コード例 #19
0
 /**
  * @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;
 }
コード例 #20
0
ファイル: RegisterForm.class.php プロジェクト: jacboy/WCF
 /**
  * @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;
 }
コード例 #21
0
	/**
	 * Validates the cookie password.
	 * 
	 * @param	wcf\data\user\User	$user
	 * @param	string			$password
	 * @return	boolean
	 */
	protected function checkCookiePassword($user, $password) {
		return $user->checkCookiePassword($password);
	}
コード例 #22
0
	/**
	 * Returns a user object by given login name.
	 * 
	 * @param	string			$login
	 * @return	wcf\data\user\User
	 */
	protected function getUserByLogin($login) {
		return User::getUserByUsername($login);
	}
コード例 #23
0
 /**
  * @see	\wcf\system\option\ISearchableConditionUserOption::addCondition()
  */
 public function addCondition(UserList $userList, Option $option, $value)
 {
     $ageFrom = intval($value['ageFrom']);
     $ageTo = intval($value['ageTo']);
     if ($ageFrom < 0 || $ageFrom > 120 || $ageTo < 0 || $ageTo > 120) {
         return false;
     }
     $dateFrom = DateUtil::getDateTimeByTimestamp(TIME_NOW)->sub(new \DateInterval('P' . ($ageTo + 1) . 'Y'))->add(new \DateInterval('P1D'));
     $dateTo = DateUtil::getDateTimeByTimestamp(TIME_NOW)->sub(new \DateInterval('P' . $ageFrom . 'Y'));
     $userList->getConditionBuilder()->add('user_option_value.userOption' . User::getUserOptionID('birthdayShowYear') . ' = ?', array(1));
     if ($ageFrom && $ageTo) {
         $userList->getConditionBuilder()->add('user_option_value.userOption' . $option->optionID . ' BETWEEN DATE(?) AND DATE(?)', array($dateFrom->format('Y-m-d'), $dateTo->format('Y-m-d')));
     } else {
         if ($ageFrom) {
             $userList->getConditionBuilder()->add('user_option_value.userOption' . $option->optionID . ' BETWEEN DATE(?) AND DATE(?)', array('1893-01-01', $dateTo->format('Y-m-d')));
         } else {
             $userList->getConditionBuilder()->add('user_option_value.userOption' . $option->optionID . ' BETWEEN DATE(?) AND DATE(?)', array($dateFrom->format('Y-m-d'), DateUtil::getDateTimeByTimestamp(TIME_NOW)->add(new \DateInterval('P1D'))->format('Y-m-d')));
         }
     }
 }
コード例 #24
0
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->username)) {
         throw new UserInputException('username');
     }
     $this->user = User::getUserByUsername($this->username);
     if (!$this->user->userID) {
         throw new UserInputException('username', 'notFound');
     }
     if ($this->subscription->subscriptionLength) {
         $this->endDateTime = \DateTime::createFromFormat('Y-m-d', $this->endDate, new \DateTimeZone('UTC'));
         if ($this->endDateTime === false || $this->endDateTime->getTimestamp() < TIME_NOW) {
             throw new UserInputException('endDate');
         }
     }
 }
コード例 #25
0
ファイル: LoginForm.class.php プロジェクト: nick-strohm/WCF
 /**
  * @see	\wcf\page\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (!empty($_REQUEST['url'])) {
         $this->url = StringUtil::trim($_REQUEST['url']);
         // discard URL if it is not an absolute URL of local content
         if (!ApplicationHandler::getInstance()->isInternalURL($this->url)) {
             $this->url = '';
         }
     }
     // check authentication failures
     if (ENABLE_USER_AUTHENTICATION_FAILURE) {
         $failures = UserAuthenticationFailure::countIPFailures(UserUtil::getIpAddress());
         if (USER_AUTHENTICATION_FAILURE_IP_BLOCK && $failures >= USER_AUTHENTICATION_FAILURE_IP_BLOCK) {
             throw new NamedUserException(WCF::getLanguage()->getDynamicVariable('wcf.user.login.blocked'));
         }
         if (USER_AUTHENTICATION_FAILURE_IP_CAPTCHA && $failures >= USER_AUTHENTICATION_FAILURE_IP_CAPTCHA) {
             $this->useCaptcha = true;
         } else {
             if (USER_AUTHENTICATION_FAILURE_USER_CAPTCHA) {
                 if (isset($_POST['username'])) {
                     $user = User::getUserByUsername(StringUtil::trim($_POST['username']));
                     if (!$user->userID) {
                         $user = User::getUserByEmail(StringUtil::trim($_POST['username']));
                     }
                     if ($user->userID) {
                         $failures = UserAuthenticationFailure::countUserFailures($user->userID);
                         if (USER_AUTHENTICATION_FAILURE_USER_CAPTCHA && $failures >= USER_AUTHENTICATION_FAILURE_USER_CAPTCHA) {
                             $this->useCaptcha = true;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #26
0
 /**
  * @see	\wcf\page\MultipleLinkPage::initObjectList
  */
 protected function initObjectList()
 {
     parent::initObjectList();
     $objectTypeIDs = array();
     foreach (ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.attachment.objectType') as $objectType) {
         if (!$objectType->private) {
             $objectTypeIDs[] = $objectType->objectTypeID;
         }
     }
     if (!empty($objectTypeIDs)) {
         $this->objectList->getConditionBuilder()->add('attachment.objectTypeID IN (?)', array($objectTypeIDs));
     } else {
         $this->objectList->getConditionBuilder()->add('1 = 0');
     }
     $this->objectList->getConditionBuilder()->add("attachment.tmpHash = ''");
     // get data
     $this->stats = $this->objectList->getStats();
     $this->availableFileTypes = $this->objectList->getAvailableFileTypes();
     // filter
     if (!empty($this->username)) {
         $user = User::getUserByUsername($this->username);
         if ($user->userID) {
             $this->objectList->getConditionBuilder()->add('attachment.userID = ?', array($user->userID));
         }
     }
     if (!empty($this->filename)) {
         $this->objectList->getConditionBuilder()->add('attachment.filename LIKE ?', array($this->filename . '%'));
     }
     if (!empty($this->fileType)) {
         $this->objectList->getConditionBuilder()->add('attachment.fileType LIKE ?', array($this->fileType));
     }
 }
コード例 #27
0
 /**
  * Validates parameters to assign a user.
  */
 public function validateAssignUser()
 {
     $this->moderationQueueEditor = $this->getSingleObject();
     $this->readInteger('assignedUserID', true);
     if ($this->parameters['assignedUserID'] && $this->parameters['assignedUserID'] != -1) {
         if ($this->parameters['assignedUserID'] != WCF::getUser()->userID && $this->parameters['assignedUserID'] != $this->moderationQueueEditor->assignedUserID) {
             // user id is either faked or changed during viewing, use database value instead
             $this->parameters['assignedUserID'] = $this->moderationQueueEditor->assignedUserID;
         }
     }
     if ($this->parameters['assignedUserID'] == -1) {
         $this->readString('assignedUsername');
         $this->user = User::getUserByUsername($this->parameters['assignedUsername']);
         if (!$this->user->userID) {
             throw new UserInputException('assignedUsername', 'notFound');
         }
         // get handler
         $objectType = ObjectTypeCache::getInstance()->getObjectType($this->moderationQueueEditor->objectTypeID);
         if (!$objectType->getProcessor()->isAffectedUser($this->moderationQueueEditor->getDecoratedObject(), $this->user->userID)) {
             throw new UserInputException('assignedUsername', 'notAffected');
         }
         $this->parameters['assignedUserID'] = $this->user->userID;
         $this->parameters['assignedUsername'] = '';
     } else {
         $this->user = new User($this->parameters['assignedUserID']);
     }
 }
コード例 #28
0
 /**
  * Sends the mail notification.
  * 
  * @param	\wcf\data\user\notification\UserNotification			$notification
  * @param	\wcf\data\user\User						$user
  * @param	\wcf\system\user\notification\event\IUserNotificationEvent	$event
  */
 public function sendInstantMailNotification(UserNotification $notification, User $user, IUserNotificationEvent $event)
 {
     // no notifications for disabled or banned users
     if ($user->activationCode) {
         return;
     }
     if ($user->banned) {
         return;
     }
     // recipient's language
     $event->setLanguage($user->getLanguage());
     // add mail header
     $message = $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.header', array('user' => $user)) . "\n\n";
     // get message
     $message .= $event->getEmailMessage();
     // append notification mail footer
     $token = $user->notificationMailToken;
     if (!$token) {
         // generate token if not present
         $token = mb_substr(StringUtil::getHash(serialize(array($user->userID, StringUtil::getRandomID()))), 0, 20);
         $editor = new UserEditor($user);
         $editor->update(array('notificationMailToken' => $token));
     }
     $message .= "\n\n" . $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.footer', array('user' => $user, 'token' => $token, 'notification' => $notification));
     // build mail
     $mail = new Mail(array($user->username => $user->email), $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.subject', array('title' => $event->getEmailTitle())), $message);
     $mail->setLanguage($user->getLanguage());
     $mail->send();
 }
コード例 #29
0
 /**
  * @see	\wcf\system\option\ISearchableConditionUserOption::checkUser()
  */
 public function checkUser(User $user, Option $option, $value)
 {
     return mb_strtolower($user->getUserOption($option->optionName)) == mb_strtolower(StringUtil::trim($value));
 }