Пример #1
0
 /**
  *
  */
 protected function createUser($groupIDs = array())
 {
     require_once WCF_DIR . 'lib/util/StringUtil.class.php';
     require_once WCF_DIR . 'lib/data/user/UserEditor.class.php';
     return UserEditor::create($username = StringUtil::getRandomID(), $email = StringUtil::getRandomID(), $password = StringUtil::getRandomID(), $groupIDs);
 }
Пример #2
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 = '" . escapeString(self::$selectedLanguageCode) . "'";
             $row = self::getDB()->getFirstRow($sql);
             if (isset($row['languageID'])) {
                 $languageID = $row['languageID'];
             }
             // create user
             $user = UserEditor::create($username, $email, $password, array(1, 3, 4), array(), array('languageID' => $languageID), array(), false);
             // 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 Form::save()
  */
 public function save()
 {
     AbstractForm::save();
     // save language id
     $this->additionalFields['languageID'] = $this->languageID;
     // save registration ip address
     $this->additionalFields['registrationIpAddress'] = WCF::getSession()->ipAddress;
     // generate activation code
     $addDefaultGroups = true;
     if (REGISTER_ACTIVATION_METHOD == 1 || REGISTER_ACTIVATION_METHOD == 2) {
         $activationCode = UserRegistrationUtil::getActivationCode();
         $this->additionalFields['activationCode'] = $activationCode;
         $addDefaultGroups = false;
         $this->groupIDs = Group::getGroupIdsByType(array(Group::EVERYONE, Group::GUESTS));
     }
     // create
     $this->user = UserEditor::create($this->username, $this->email, $this->password, $this->groupIDs, $this->activeOptions, $this->additionalFields, $this->visibleLanguages, $addDefaultGroups);
     // update session
     WCF::getSession()->changeUser($this->user);
     // activation management
     if (REGISTER_ACTIVATION_METHOD == 0) {
         $this->message = 'wcf.user.register.success';
     }
     if (REGISTER_ACTIVATION_METHOD == 1) {
         $mail = new Mail(array($this->username => $this->email), WCF::getLanguage()->get('wcf.user.register.needActivation.mail.subject', array('PAGE_TITLE' => WCF::getLanguage()->get(PAGE_TITLE))), WCF::getLanguage()->get('wcf.user.register.needActivation.mail', array('PAGE_TITLE' => WCF::getLanguage()->get(PAGE_TITLE), '$username' => $this->username, '$userID' => $this->user->userID, '$activationCode' => $activationCode, 'PAGE_URL' => PAGE_URL, 'MAIL_ADMIN_ADDRESS' => MAIL_ADMIN_ADDRESS)));
         $mail->send();
         $this->message = 'wcf.user.register.needActivation';
     }
     if (REGISTER_ACTIVATION_METHOD == 2) {
         $this->message = 'wcf.user.register.awaitActivation';
     }
     // notify admin
     if (REGISTER_ADMIN_NOTIFICATION) {
         // get default language
         $language = WCF::getLanguage()->getLanguageID() != Language::getDefaultLanguageID() ? new Language(Language::getDefaultLanguageID()) : WCF::getLanguage();
         $language->setLocale();
         // send mail
         $mail = new Mail(MAIL_ADMIN_ADDRESS, $language->get('wcf.user.register.notification.mail.subject', array('PAGE_TITLE' => $language->get(PAGE_TITLE))), $language->get('wcf.user.register.notification.mail', array('PAGE_TITLE' => $language->get(PAGE_TITLE), '$username' => $this->username)));
         $mail->send();
         WCF::getLanguage()->setLocale();
     }
     // delete captcha
     if (REGISTER_USE_CAPTCHA && !WCF::getSession()->getVar('captchaDone')) {
         $this->captcha->delete();
     }
     WCF::getSession()->unregister('captchaDone');
     // login user
     UserAuth::getInstance()->storeAccessData($this->user, $this->username, $this->password);
     $this->saved();
     // forward to index page
     WCF::getTPL()->assign(array('url' => 'index.php' . SID_ARG_1ST, 'message' => WCF::getLanguage()->get($this->message, array('$username' => $this->username, '$email' => $this->email))));
     WCF::getTPL()->display('redirect');
     exit;
 }
Пример #4
0
 /**
  * @see Form::save()
  */
 public function save()
 {
     AbstractForm::save();
     // create
     $this->additionalFields['languageID'] = $this->languageID;
     require_once WCF_DIR . 'lib/data/user/UserEditor.class.php';
     $this->user = UserEditor::create($this->username, $this->email, $this->password, $this->groupIDs, $this->activeOptions, $this->additionalFields, $this->visibleLanguages);
     $this->saved();
     // show empty add form
     WCF::getTPL()->assign(array('success' => true, 'newUser' => $this->user));
     // reset values
     $this->username = $this->email = $this->confirmEmail = $this->password = $this->confirmPassword = '';
     $this->groupIDs = array();
     $this->languageID = $this->getDefaultFormLanguageID();
     foreach ($this->activeOptions as $key => $option) {
         unset($this->activeOptions[$key]['optionValue']);
     }
 }