/** * @see \wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'register') { // if the username field is an email, save it as email for the registration if (UserUtil::isValidEmail($this->username)) { WCF::getSession()->register('__email', $this->username); } else { WCF::getSession()->register('__username', $this->username); } WCF::getSession()->update(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Register')); exit; } $this->useCookies = 0; if (isset($_POST['useCookies'])) { $this->useCookies = intval($_POST['useCookies']); } }
/** * Throws a UserInputException if the email is not unique or not valid. * * @param string $email * @param string $confirmEmail */ protected function validateEmail($email, $confirmEmail) { if (empty($email)) { throw new UserInputException('email'); } // check for valid email (one @ etc.) if (!UserUtil::isValidEmail($email)) { throw new UserInputException('email', 'notValid'); } // Check if email exists already. if (!UserUtil::isAvailableEmail($email)) { throw new UserInputException('email', 'notUnique'); } // check confirm input if (StringUtil::toLowerCase($email) != StringUtil::toLowerCase($confirmEmail)) { throw new UserInputException('confirmEmail', 'notEqual'); } }
/** * @see \wcf\form\IForm::validate() */ public function validate() { if (!WCF::getUser()->userID) { if (empty($this->email)) { throw new UserInputException('email'); } if (!UserUtil::isValidEmail($this->email)) { throw new UserInputException('email', 'notValid'); } } if (empty($this->subject)) { throw new UserInputException('subject'); } if (empty($this->message)) { throw new UserInputException('message'); } parent::validate(); }
/** * 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'); }
/** * @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(); }