From: joshuaruesweg Date: Sat, 10 Jul 2021 09:44:09 +0000 (+0200) Subject: Merge branch '5.3' X-Git-Tag: 5.4.0~17 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ca14204a954abf4f90d8cc124260b52b594802c7;p=GitHub%2FWoltLab%2FWCF.git Merge branch '5.3' --- ca14204a954abf4f90d8cc124260b52b594802c7 diff --cc wcfsetup/install/files/lib/form/RegisterNewActivationCodeForm.class.php index bf65c3a255,7fbe728505..ae558d9b3d --- a/wcfsetup/install/files/lib/form/RegisterNewActivationCodeForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterNewActivationCodeForm.class.php @@@ -21,218 -19,190 +21,215 @@@ use wcf\util\UserUtil /** * Shows the new activation code form. * - * @author Marcel Werk - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\Form + * @author Marcel Werk + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Form */ -class RegisterNewActivationCodeForm extends AbstractForm { - /** - * username - * @var string - */ - public $username = ''; - - /** - * password - * @var string - */ - public $password = ''; - - /** - * email - * @var string - */ - public $email = ''; - - /** - * user object - * @var User - */ - public $user = null; - - /** - * @inheritDoc - */ - public function readFormParameters() { - parent::readFormParameters(); - - if (isset($_POST['username'])) $this->username = StringUtil::trim($_POST['username']); - if (isset($_POST['password'])) $this->password = $_POST['password']; - if (isset($_POST['email'])) $this->email = StringUtil::trim($_POST['email']); - } - - /** - * @inheritDoc - */ - public function validate() { - parent::validate(); - - // username - $this->validateUsername(); - - // password - $this->validatePassword(); - - // email - $this->validateEmail(); - } - - /** - * Validates the username. - */ - public function validateUsername() { - if (empty($this->username)) { - throw new UserInputException('username'); - } - - $this->user = User::getUserByUsername($this->username); - if (!$this->user->userID) { - throw new UserInputException('username', 'notFound'); - } - - if ($this->user->isEmailConfirmed()) { - throw new UserInputException('username', 'alreadyEnabled'); - } - - if (!empty($this->user->getBlacklistMatches())) { - throw new PermissionDeniedException(); - } - } - - /** - * Validates the password. - */ - public function validatePassword() { - if (empty($this->password)) { - throw new UserInputException('password'); - } - - // check password - if (!$this->user->checkPassword($this->password)) { - throw new UserInputException('password', 'false'); - } - } - - /** - * 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', 'invalid'); - } - - // Check if email exists already. - if (!UserUtil::isAvailableEmail($this->email)) { - throw new UserInputException('email', 'notUnique'); - } - } - else { - $this->email = ''; - } - } - } - - /** - * @inheritDoc - */ - public function save() { - parent::save(); - - // save user - $parameters = ['emailConfirmed' => \bin2hex(\random_bytes(20))]; - if (!empty($this->email)) $parameters['email'] = $this->email; - $this->objectAction = new UserAction([$this->user], 'update', [ - 'data' => array_merge($this->additionalFields, $parameters) - ]); - $this->objectAction->executeAction(); - - // reload user to reflect changes - $this->user = new User($this->user->userID); - - // send activation mail - $email = new Email(); - $email->addRecipient(new UserMailbox($this->user)); - $email->setSubject(WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject')); - $email->setBody(new MimePartFacade([ - new RecipientAwareTextMimePart('text/html', 'email_registerNeedActivation'), - new RecipientAwareTextMimePart('text/plain', 'email_registerNeedActivation') - ])); - $email->send(); - $this->saved(); - - // forward to index page - HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->getDynamicVariable('wcf.user.newActivationCode.success', ['email' => !empty($this->email) ? $this->email : $this->user->email]), 10); - exit; - } - - /** - * @inheritDoc - */ - public function readData() { - parent::readData(); - - if (empty($_POST) && WCF::getUser()->userID) { - $this->username = WCF::getUser()->username; - } - } - - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign([ - 'username' => $this->username, - 'password' => $this->password, - 'email' => $this->email - ]); - } - - /** - * @inheritDoc - */ - public function show() { - if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) { - throw new IllegalLinkException(); - } - - if ($this->user === null && !empty(WCF::getUser()->getBlacklistMatches())) { - throw new PermissionDeniedException(); - } - - parent::show(); - } +class RegisterNewActivationCodeForm extends AbstractForm +{ + /** + * username + * @var string + */ + public $username = ''; + + /** + * password + * @var string + */ + public $password = ''; + + /** + * email + * @var string + */ + public $email = ''; + + /** + * user object + * @var User + */ + public $user; + + /** + * @inheritDoc + */ + public function readFormParameters() + { + parent::readFormParameters(); + + if (isset($_POST['username'])) { + $this->username = StringUtil::trim($_POST['username']); + } + if (isset($_POST['password'])) { + $this->password = $_POST['password']; + } + if (isset($_POST['email'])) { + $this->email = StringUtil::trim($_POST['email']); + } + } + + /** + * @inheritDoc + */ + public function validate() + { + parent::validate(); + + // username + $this->validateUsername(); + + // password + $this->validatePassword(); + + // email + $this->validateEmail(); + } + + /** + * Validates the username. + */ + public function validateUsername() + { + if (empty($this->username)) { + throw new UserInputException('username'); + } + + $this->user = User::getUserByUsername($this->username); + if (!$this->user->userID) { + throw new UserInputException('username', 'notFound'); + } + + if ($this->user->isEmailConfirmed()) { + throw new UserInputException('username', 'alreadyEnabled'); + } + + if (!empty($this->user->getBlacklistMatches())) { + throw new PermissionDeniedException(); + } + } + + /** + * Validates the password. + */ + public function validatePassword() + { + if (empty($this->password)) { + throw new UserInputException('password'); + } + + // check password + if (!$this->user->checkPassword($this->password)) { + throw new UserInputException('password', 'false'); + } + } + + /** + * 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', 'invalid'); + } + + // Check if email exists already. + if (!UserUtil::isAvailableEmail($this->email)) { + throw new UserInputException('email', 'notUnique'); + } + } else { + $this->email = ''; + } + } + } + + /** + * @inheritDoc + */ + public function save() + { + parent::save(); + - // generate activation code - $activationCode = UserRegistrationUtil::getActivationCode(); - - // save user - $parameters = ['activationCode' => $activationCode]; ++ // save user ++ $parameters = ['emailConfirmed' => \bin2hex(\random_bytes(20))]; + if (!empty($this->email)) { + $parameters['email'] = $this->email; + } + $this->objectAction = new UserAction([$this->user], 'update', [ + 'data' => \array_merge($this->additionalFields, $parameters), + ]); + $this->objectAction->executeAction(); + + // reload user to reflect changes + $this->user = new User($this->user->userID); + + // send activation mail + $email = new Email(); + $email->addRecipient(new UserMailbox($this->user)); + $email->setSubject(WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject')); + $email->setBody(new MimePartFacade([ + new RecipientAwareTextMimePart('text/html', 'email_registerNeedActivation'), + new RecipientAwareTextMimePart('text/plain', 'email_registerNeedActivation'), + ])); + $email->send(); + $this->saved(); + + // forward to index page + HeaderUtil::delayedRedirect( + LinkHandler::getInstance()->getLink(), + WCF::getLanguage()->getDynamicVariable( + 'wcf.user.newActivationCode.success', + ['email' => !empty($this->email) ? $this->email : $this->user->email] + ), + 10 + ); + + exit; + } + + /** + * @inheritDoc + */ + public function readData() + { + parent::readData(); + + if (empty($_POST) && WCF::getUser()->userID) { + $this->username = WCF::getUser()->username; + } + } + + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'username' => $this->username, + 'password' => $this->password, + 'email' => $this->email, + ]); + } + + /** + * @inheritDoc + */ + public function show() + { + if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) { + throw new IllegalLinkException(); + } + + if ($this->user === null && !empty(WCF::getUser()->getBlacklistMatches())) { + throw new PermissionDeniedException(); + } + + parent::show(); + } }