-{include file='header' __disableAds=true}
+{include file='authFlowHeader'}
{if $__wcf->user->userID && !$__wcf->user->isEmailConfirmed()}
<woltlab-core-notice type="info">{lang}wcf.user.registerActivation.info{/lang}</woltlab-core-notice>
{/if}
-{include file='formError'}
+{@$form->getHtml()}
-<form method="post" action="{link controller='RegisterActivation'}{/link}">
- <div class="section">
- <dl{if $errorField == 'username'} class="formError"{/if}>
- <dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
- <dd>
- <input type="text" id="username" name="username" value="{$username}" required class="medium">
- {if $errorField == 'username'}
- <small class="innerError">
- {if $errorType == 'empty'}
- {lang}wcf.global.form.error.empty{/lang}
- {else}
- {lang}wcf.user.username.error.{@$errorType}{/lang}
- {/if}
- </small>
- {/if}
- </dd>
- </dl>
-
- <dl{if $errorField == 'activationCode'} class="formError"{/if}>
- <dt><label for="activationCode">{lang}wcf.user.activationCode{/lang}</label></dt>
- <dd>
- <input type="text" id="activationCode" maxlength="40" name="activationCode" value="{$activationCode}" required class="medium">
- {if $errorField == 'activationCode'}
- <small class="innerError">
- {if $errorType == 'empty'}
- {lang}wcf.global.form.error.empty{/lang}
- {else}
- {lang}wcf.user.activationCode.error.{@$errorType}{/lang}
- {/if}
- </small>
- {/if}
- <small><a href="{link controller='RegisterNewActivationCode'}{/link}">{lang}wcf.user.newActivationCode{/lang}</a></small>
- </dd>
- </dl>
-
- {event name='fields'}
- </div>
-
- {event name='sections'}
-
- <div class="formSubmit">
- <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
- {csrfToken}
- </div>
-</form>
-
-{include file='footer' __disableAds=true}
+{include file='authFlowFooter'}
use wcf\data\user\User;
use wcf\data\user\UserAction;
-use wcf\system\event\EventHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\NamedUserException;
use wcf\system\exception\PermissionDeniedException;
-use wcf\system\exception\UserInputException;
+use wcf\system\form\builder\container\FormContainer;
+use wcf\system\form\builder\field\TextFormField;
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\system\form\builder\field\validation\FormFieldValidator;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\HeaderUtil;
/**
* Shows the user activation form.
*
- * @author Marcel Werk
+ * @author Marcel Werk
* @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
-class RegisterActivationForm extends AbstractForm
+final class RegisterActivationForm extends AbstractFormBuilderForm
{
- /**
- * username
- * @var string
- */
- public $username;
-
- /**
- * activation code
- * @var string
- */
- public $activationCode = '';
-
- /**
- * User object
- * @var User
- */
- public $user;
+ public User $user;
/**
* @inheritDoc
*/
- public function readParameters()
+ protected function createForm()
{
- parent::readParameters();
-
- if (!empty($_GET['u'])) {
- $userID = \intval($_GET['u']);
- $this->user = new User($userID);
- if ($this->user->userID) {
- $this->username = $this->user->username;
- }
+ parent::createForm();
+
+ $this->form->appendChild(
+ FormContainer::create('data')
+ ->appendChildren([
+ TextFormField::create('username')
+ ->label('wcf.user.username')
+ ->required()
+ ->autoFocus()
+ ->maximumLength(255)
+ ->addValidator(new FormFieldValidator(
+ 'usernameValidator',
+ $this->validateUsername(...)
+ )),
+ TextFormField::create('activationCode')
+ ->label('wcf.user.activationCode')
+ ->description('<a href="' . StringUtil::encodeHTML(LinkHandler::getInstance()->getControllerLink(RegisterNewActivationCodeForm::class)) . '">' . WCF::getLanguage()->get('wcf.user.newActivationCode') . '</a>')
+ ->required()
+ ->maximumLength(40)
+ ->addValidator(new FormFieldValidator(
+ 'activationCodeValidator',
+ $this->validateActivationCode(...)
+ ))
+ ])
+ );
+ }
+
+ private function validateUsername(TextFormField $formField): void
+ {
+ $value = StringUtil::trim($formField->getValue());
+ $this->user = User::getUserByUsername($value);
+
+ if (!$this->user->userID) {
+ $formField->addValidationError(
+ new FormFieldValidationError(
+ 'notFound',
+ 'wcf.user.username.error.notFound',
+ [
+ 'username' => $value,
+ ]
+ )
+ );
+ }
+
+ if ($this->user->isEmailConfirmed()) {
+ throw new NamedUserException(
+ WCF::getLanguage()->get('wcf.user.registerActivation.error.userAlreadyEnabled')
+ );
}
- if (!empty($_GET['a'])) {
- $this->activationCode = StringUtil::trim($_GET['a']);
+
+ if (!empty($this->user->getBlacklistMatches())) {
+ throw new PermissionDeniedException();
}
}
- /**
- * @inheritDoc
- */
- public function readFormParameters()
+ private function validateActivationCode(TextFormField $formField): void
{
- parent::readFormParameters();
-
- if (isset($_POST['username'])) {
- $this->username = StringUtil::trim($_POST['username']);
- $this->user = User::getUserByUsername($this->username);
+ if (!isset($this->user)) {
+ return;
}
- if (isset($_POST['activationCode'])) {
- $this->activationCode = StringUtil::trim($_POST['activationCode']);
+
+ if (!\hash_equals($this->user->emailConfirmed, StringUtil::trim($formField->getValue()))) {
+ $formField->addValidationError(
+ new FormFieldValidationError(
+ 'invalid',
+ 'wcf.user.activationCode.error.invalid'
+ )
+ );
}
}
/**
* @inheritDoc
*/
- public function validate()
+ public function show()
{
- EventHandler::getInstance()->fireAction($this, 'validate');
-
- // check given user name
- if ($this->user === null || !$this->user->userID) {
- throw new UserInputException('username', 'notFound');
- }
-
- // user email is already confirmed
- if ($this->user->isEmailConfirmed()) {
- throw new NamedUserException(
- WCF::getLanguage()->get('wcf.user.registerActivation.error.userAlreadyEnabled')
- );
+ if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) {
+ throw new IllegalLinkException();
}
- // check given activation code
- if (!\hash_equals($this->user->emailConfirmed, $this->activationCode)) {
- throw new UserInputException('activationCode', 'invalid');
+ if (empty($_POST) && !empty($_GET['u']) && !empty($_GET['a'])) {
+ $user = new User(\intval($_GET['u']));
+ $_POST['username'] = $user->userID ? $user->username : '';
+ $_POST['activationCode'] = $_GET['a'];
+ $_REQUEST['t'] = WCF::getSession()->getSecurityToken();
}
- if (!empty($this->user->getBlacklistMatches())) {
+ if (!empty(WCF::getUser()->getBlacklistMatches())) {
throw new PermissionDeniedException();
}
+
+ parent::show();
}
/**
*/
public function save()
{
- parent::save();
+ AbstractForm::save();
- // enable user
$this->objectAction = new UserAction([$this->user], 'confirmEmail', ['skipNotification' => true]);
$this->objectAction->executeAction();
$this->saved();
exit;
}
-
- /**
- * @inheritDoc
- */
- public function assignVariables()
- {
- parent::assignVariables();
-
- WCF::getTPL()->assign([
- 'username' => $this->username,
- 'activationCode' => $this->activationCode,
- ]);
- }
-
- /**
- * @inheritDoc
- */
- public function show()
- {
- if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) {
- throw new IllegalLinkException();
- }
-
- if (empty($_POST) && $this->user !== null && $this->activationCode != 0) {
- $this->submit();
- }
-
- if ($this->user === null && !empty(WCF::getUser()->getBlacklistMatches())) {
- throw new PermissionDeniedException();
- }
-
- parent::show();
- }
}