Exemplo n.º 1
0
 /**
  * Shows the page for creating the admin account.
  */
 protected function createUser()
 {
     $errorType = $errorField = $username = $email = $confirmEmail = $password = $confirmPassword = '';
     $username = '';
     $email = $confirmEmail = '';
     $password = $confirmPassword = '';
     if (isset($_POST['send']) || self::$developerMode) {
         if (isset($_POST['send'])) {
             if (isset($_POST['username'])) {
                 $username = StringUtil::trim($_POST['username']);
             }
             if (isset($_POST['email'])) {
                 $email = StringUtil::trim($_POST['email']);
             }
             if (isset($_POST['confirmEmail'])) {
                 $confirmEmail = StringUtil::trim($_POST['confirmEmail']);
             }
             if (isset($_POST['password'])) {
                 $password = $_POST['password'];
             }
             if (isset($_POST['confirmPassword'])) {
                 $confirmPassword = $_POST['confirmPassword'];
             }
         } else {
             $username = $password = $confirmPassword = '******';
             $email = $confirmEmail = '*****@*****.**';
         }
         // error handling
         try {
             // username
             if (empty($username)) {
                 throw new UserInputException('username');
             }
             if (!UserUtil::isValidUsername($username)) {
                 throw new UserInputException('username', 'notValid');
             }
             // e-mail address
             if (empty($email)) {
                 throw new UserInputException('email');
             }
             if (!UserUtil::isValidEmail($email)) {
                 throw new UserInputException('email', 'notValid');
             }
             // confirm e-mail address
             if ($email != $confirmEmail) {
                 throw new UserInputException('confirmEmail', 'notEqual');
             }
             // password
             if (empty($password)) {
                 throw new UserInputException('password');
             }
             // confirm e-mail address
             if ($password != $confirmPassword) {
                 throw new UserInputException('confirmPassword', 'notEqual');
             }
             // no errors
             // init database connection
             $this->initDB();
             // get language id
             $languageID = 0;
             $sql = "SELECT\tlanguageID\n\t\t\t\t\tFROM\twcf" . WCF_N . "_language\n\t\t\t\t\tWHERE\tlanguageCode = ?";
             $statement = self::getDB()->prepareStatement($sql);
             $statement->execute(array(self::$selectedLanguageCode));
             $row = $statement->fetchArray();
             if (isset($row['languageID'])) {
                 $languageID = $row['languageID'];
             }
             if (!$languageID) {
                 $languageID = LanguageFactory::getInstance()->getDefaultLanguageID();
             }
             // create user
             $data = array('data' => array('email' => $email, 'languageID' => $languageID, 'password' => $password, 'username' => $username), 'groups' => array(1, 3, 4), 'languages' => array($languageID));
             $userAction = new UserAction(array(), 'create', $data);
             $userAction->executeAction();
             // go to next step
             $this->gotoNextStep('installPackages');
             exit;
         } catch (UserInputException $e) {
             $errorField = $e->getField();
             $errorType = $e->getType();
         }
     }
     WCF::getTPL()->assign(array('errorField' => $errorField, 'errorType' => $errorType, 'username' => $username, 'email' => $email, 'confirmEmail' => $confirmEmail, 'password' => $password, 'confirmPassword' => $confirmPassword, 'nextStep' => 'createUser'));
     WCF::getTPL()->display('stepCreateUser');
 }
Exemplo n.º 2
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');
		}
	}
Exemplo n.º 3
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();
     }
 }