コード例 #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\system\user\authentication\DefaultUserAuthentication::getUserByLogin()
  */
 protected function getUserByLogin($login)
 {
     return User::getUserByEmail($login);
 }
コード例 #3
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;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #4
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;
 }