From a92854e3f61f776840de8723e86bd9201cd1a90e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 17 Nov 2020 11:07:24 +0100 Subject: [PATCH] Add support for redirectUrl to MultifactorAuthenticationForm --- .../templates/multifactorAuthentication.tpl | 2 +- .../files/lib/acp/form/LoginForm.class.php | 4 ++- .../MultifactorAuthenticationForm.class.php | 25 +++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/com.woltlab.wcf/templates/multifactorAuthentication.tpl b/com.woltlab.wcf/templates/multifactorAuthentication.tpl index fbcefda83b..0de2758747 100644 --- a/com.woltlab.wcf/templates/multifactorAuthentication.tpl +++ b/com.woltlab.wcf/templates/multifactorAuthentication.tpl @@ -7,7 +7,7 @@
    {foreach from=$setups item='_setup'} getId() == $_setup->getId()} class="active"{/if}> - {lang}wcf.user.security.multifactor.{$_setup->getObjectType()->objectType}{/lang} + {lang}wcf.user.security.multifactor.{$_setup->getObjectType()->objectType}{/lang} {/foreach}
diff --git a/wcfsetup/install/files/lib/acp/form/LoginForm.class.php b/wcfsetup/install/files/lib/acp/form/LoginForm.class.php index 208535a649..4d5b28566c 100755 --- a/wcfsetup/install/files/lib/acp/form/LoginForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LoginForm.class.php @@ -213,7 +213,9 @@ class LoginForm extends AbstractCaptchaForm { */ protected function performRedirect(bool $needsMultifactor = false) { if ($needsMultifactor) { - $this->url = LinkHandler::getInstance()->getControllerLink(MultifactorAuthenticationForm::class); + $this->url = LinkHandler::getInstance()->getControllerLink(MultifactorAuthenticationForm::class, [ + 'url' => $this->url, + ]); } if (!empty($this->url)) { diff --git a/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php b/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php index d9483ffb72..c8041e8e5d 100644 --- a/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php +++ b/wcfsetup/install/files/lib/form/MultifactorAuthenticationForm.class.php @@ -3,12 +3,14 @@ namespace wcf\form; use wcf\data\object\type\ObjectType; use wcf\data\user\User; use wcf\form\AbstractFormBuilderForm; +use wcf\system\application\ApplicationHandler; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\PermissionDeniedException; use wcf\system\request\LinkHandler; use wcf\system\user\multifactor\IMultifactorMethod; use wcf\system\user\multifactor\Setup; use wcf\system\WCF; +use wcf\util\HeaderUtil; /** * Represents the multi-factor authentication form. @@ -52,6 +54,11 @@ class MultifactorAuthenticationForm extends AbstractFormBuilderForm { */ private $setup; + /** + * @var string + */ + public $redirectUrl; + /** * @inheritDoc */ @@ -87,6 +94,10 @@ class MultifactorAuthenticationForm extends AbstractFormBuilderForm { \assert($this->method->getDefinition()->definitionName === 'com.woltlab.wcf.multifactor'); $this->processor = $this->method->getProcessor(); + + if (!empty($_GET['url']) && ApplicationHandler::getInstance()->isInternalURL($_GET['url'])) { + $this->redirectUrl = $_GET['url']; + } } /** @@ -120,11 +131,13 @@ class MultifactorAuthenticationForm extends AbstractFormBuilderForm { public function saved() { AbstractForm::saved(); - $this->form->cleanup(); - $this->buildForm(); - - // TODO: Proper success message and hiding of the form. - $this->form->showSuccessMessage(true); + if ($this->redirectUrl) { + HeaderUtil::redirect($this->redirectUrl); + } + else { + HeaderUtil::redirect(LinkHandler::getInstance()->getLink()); + } + exit; } /** @@ -133,6 +146,7 @@ class MultifactorAuthenticationForm extends AbstractFormBuilderForm { protected function setFormAction() { $this->form->action(LinkHandler::getInstance()->getControllerLink(static::class, [ 'object' => $this->setup, + 'url' => $this->redirectUrl, ])); } @@ -146,6 +160,7 @@ class MultifactorAuthenticationForm extends AbstractFormBuilderForm { 'setups' => $this->setups, 'user' => $this->user, 'setup' => $this->setup, + 'redirectUrl' => $this->redirectUrl, ]); } } -- 2.20.1