/**
  * Validates the given username.
  * 
  * @return	array
  */
 public function validateUsername()
 {
     if (!UserRegistrationUtil::isValidUsername($this->parameters['username'])) {
         return array('isValid' => false, 'error' => 'notValid');
     }
     if (!UserUtil::isAvailableUsername($this->parameters['username'])) {
         return array('isValid' => false, 'error' => 'notUnique');
     }
     return array('isValid' => true);
 }
Ejemplo n.º 2
0
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // password
     if (!WCF::getUser()->authData) {
         if (empty($this->password)) {
             throw new UserInputException('password');
         }
         if (!WCF::getUser()->checkPassword($this->password)) {
             throw new UserInputException('password', 'false');
         }
     }
     // user name
     if (WCF::getSession()->getPermission('user.profile.canRename') && $this->username != WCF::getUser()->username) {
         if (mb_strtolower($this->username) != mb_strtolower(WCF::getUser()->username)) {
             if (WCF::getUser()->lastUsernameChange + WCF::getSession()->getPermission('user.profile.renamePeriod') * 86400 > TIME_NOW) {
                 throw new UserInputException('username', 'alreadyRenamed');
             }
             // checks for forbidden chars (e.g. the ",")
             if (!UserRegistrationUtil::isValidUsername($this->username)) {
                 throw new UserInputException('username', 'notValid');
             }
             // checks if user name exists already.
             if (!UserUtil::isAvailableUsername($this->username)) {
                 throw new UserInputException('username', 'notUnique');
             }
         }
     }
     // password
     if (!WCF::getUser()->authData) {
         if (!empty($this->newPassword) || !empty($this->confirmNewPassword)) {
             if (empty($this->newPassword)) {
                 throw new UserInputException('newPassword');
             }
             if (empty($this->confirmNewPassword)) {
                 throw new UserInputException('confirmNewPassword');
             }
             if (!UserRegistrationUtil::isSecurePassword($this->newPassword)) {
                 throw new UserInputException('newPassword', 'notSecure');
             }
             if ($this->newPassword != $this->confirmNewPassword) {
                 throw new UserInputException('confirmNewPassword', 'notEqual');
             }
         }
     }
     // email
     if (WCF::getSession()->getPermission('user.profile.canChangeEmail') && $this->email != WCF::getUser()->email && $this->email != WCF::getUser()->newEmail) {
         if (empty($this->email)) {
             throw new UserInputException('email');
         }
         // checks if only letter case has changed
         if (mb_strtolower($this->email) != mb_strtolower(WCF::getUser()->email)) {
             // check for valid email (one @ etc.)
             if (!UserRegistrationUtil::isValidEmail($this->email)) {
                 throw new UserInputException('email', 'notValid');
             }
             // checks if email already exists.
             if (!UserUtil::isAvailableEmail($this->email)) {
                 throw new UserInputException('email', 'notUnique');
             }
         }
         // checks confirm input
         if (mb_strtolower($this->email) != mb_strtolower($this->confirmEmail)) {
             throw new UserInputException('confirmEmail', 'notEqual');
         }
     }
 }
Ejemplo n.º 3
0
	/**
	 * Throws a UserInputException if the username is not unique or not valid.
	 * 
	 * @param	string		$username
	 */
	protected function validateUsername($username) {
		if (empty($username)) {
			throw new UserInputException('username');
		}
		
		// check for forbidden chars (e.g. the ",")
		if (!UserUtil::isValidUsername($username)) {
			throw new UserInputException('username', 'notValid');
		}
		
		// Check if username exists already.
		if (!UserUtil::isAvailableUsername($username)) {
			throw new UserInputException('username', 'notUnique');
		}
	}
 /**
  * @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();
 }
Ejemplo n.º 5
0
 /**
  * Validates the username parameter.
  */
 protected function validateUsername()
 {
     if (WCF::getUser()->userID) {
         return;
     }
     try {
         $this->readString('username', false, 'data');
         if (!UserUtil::isValidUsername($this->parameters['data']['username'])) {
             throw new UserInputException('username', 'notValid');
         }
         if (!UserUtil::isAvailableUsername($this->parameters['data']['username'])) {
             throw new UserInputException('username', 'notUnique');
         }
     } catch (UserInputException $e) {
         $this->validationErrors['username'] = $e->getType();
     }
 }