コード例 #1
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))));
     }
 }
コード例 #2
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']);
     }
 }
コード例 #3
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');
     }
 }
コード例 #4
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']);
 }
コード例 #5
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));
     }
 }
コード例 #6
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);
	}
コード例 #7
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');
         }
     }
 }
コード例 #8
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;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #9
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;
 }
コード例 #10
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']);
     }
 }