/** * Validates given email address. * * @return array */ public function validateEmailAddress() { if (!UserRegistrationUtil::isValidEmail($this->parameters['email'])) { return array('isValid' => false, 'error' => 'notValid'); } if (!UserUtil::isAvailableEmail($this->parameters['email'])) { return array('isValid' => false, 'error' => 'notUnique'); } return array('isValid' => true); }
/** * @see \wcf\form\IForm::validate() */ public function validate() { EventHandler::getInstance()->fireAction($this, 'validate'); // check given user id $this->user = new User($this->userID); if (!$this->user->userID) { throw new UserInputException('u', 'notValid'); } // user is already enabled if ($this->user->reactivationCode == 0) { throw new NamedUserException(WCF::getLanguage()->get('wcf.user.emailActivation.error.emailAlreadyEnabled')); } // check whether the new email isn't unique anymore if (!UserUtil::isAvailableEmail($this->user->newEmail)) { throw new NamedUserException(WCF::getLanguage()->get('wcf.user.email.error.notUnique')); } // check given activation code if ($this->user->reactivationCode != $this->activationCode) { throw new UserInputException('a', 'notValid'); } }
/** * @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'); } } }
/** * 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'); } }
/** * Validates the email address. */ public function validateEmail() { if (!empty($this->email)) { // check whether user entered the same email, instead of leaving the input empty if (mb_strtolower($this->email) != mb_strtolower($this->user->email)) { if (!UserRegistrationUtil::isValidEmail($this->email)) { throw new UserInputException('email', 'notValid'); } // Check if email exists already. if (!UserUtil::isAvailableEmail($this->email)) { throw new UserInputException('email', 'notUnique'); } } else { $this->email = ''; } } }
/** * @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(); }