Make the MF authentication controller for ACP inherit from the frontend ones
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 19 Nov 2020 15:56:29 +0000 (16:56 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 20 Nov 2020 09:20:50 +0000 (10:20 +0100)
wcfsetup/install/files/lib/acp/form/MultifactorAuthenticationAbortForm.class.php
wcfsetup/install/files/lib/acp/form/MultifactorAuthenticationForm.class.php
wcfsetup/install/files/lib/form/MultifactorAuthenticationAbortForm.class.php

index 8ca808df6358f28bf5525903dc0a29bfe3e3f46c..a6a4ae39565d3195db8bb09471ac4758fdb015b3 100644 (file)
@@ -1,10 +1,6 @@
 <?php
 namespace wcf\acp\form;
-
-use wcf\form\AbstractForm;
-use wcf\system\exception\PermissionDeniedException;
 use wcf\system\request\LinkHandler;
-use wcf\system\WCF;
 use wcf\util\HeaderUtil;
 
 /**
@@ -16,71 +12,14 @@ use wcf\util\HeaderUtil;
  * @package    WoltLabSuite\Core\Acp\Form
  * @since      5.4
  */
-class MultifactorAuthenticationAbortForm extends AbstractForm {
-       const AVAILABLE_DURING_OFFLINE_MODE = true;
-       
-       /**
-        * @inheritDoc
-        */
-       public $useTemplate = false;
-       
-       /**
-        * @inheritDoc
-        */
-       public function readParameters() {
-               parent::readParameters();
-               
-               if (WCF::getUser()->userID) {
-                       throw new PermissionDeniedException();
-               }
-               
-               $user = WCF::getSession()->getPendingUserChange();
-               if (!$user) {
-                       $this->performRedirect();
-               }
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function save() {
-               parent::save();
-               
-               WCF::getSession()->clearPendingUserChange();
-               
-               $this->saved();
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function saved() {
-               parent::saved();
-               
-               $this->performRedirect();
-       }
-       
+class MultifactorAuthenticationAbortForm extends \wcf\form\MultifactorAuthenticationAbortForm {
        /**
         * Returns to the landing page otherwise.
         */
        protected function performRedirect() {
                HeaderUtil::redirect(
-                       LinkHandler::getInstance()->getControllerLink(LoginForm::class)
+                       LinkHandler::getInstance()->getLink('Login')
                );
                exit;
        }
-       
-       /**
-        * @inheritDoc
-        */
-       public function show() {
-               parent::show();
-               
-               // It is not expected to reach this place, because the form should
-               // never be accessed via a direct link.
-               // If we reach it nonetheless we simply redirect back to the authentication
-               // form which contains the proper button to perform the submission.
-               HeaderUtil::redirect(LinkHandler::getInstance()->getControllerLink(MultifactorAuthenticationForm::class));
-               exit;
-       }
 }
index ffa6e55cc3f3cf095c71d14c68233e6bd57930fb..6b062408ad620bf5fa9242efaa86eddc28790c1f 100644 (file)
@@ -1,18 +1,5 @@
 <?php
 namespace wcf\acp\form;
-use wcf\data\object\type\ObjectType;
-use wcf\data\user\User;
-use wcf\form\AbstractForm;
-use wcf\form\AbstractFormBuilderForm;
-use wcf\system\application\ApplicationHandler;
-use wcf\system\cache\runtime\UserProfileRuntimeCache;
-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.
@@ -23,158 +10,6 @@ use wcf\util\HeaderUtil;
  * @package    WoltLabSuite\Core\Acp\Form
  * @since      5.4
  */
-class MultifactorAuthenticationForm extends AbstractFormBuilderForm {
-       const AVAILABLE_DURING_OFFLINE_MODE = true;
-       
-       /**
-        * @inheritDoc
-        */
-       public $formAction = 'authenticate';
-       
-       /**
-        * @var User
-        */
-       private $user;
-       
-       /**
-        * @var Setup[]
-        */
-       private $setups;
-       
-       /**
-        * @var ObjectType
-        */
-       private $method;
-       
-       /**
-        * @var IMultifactorMethod
-        */
-       private $processor;
-       
-       /**
-        * @var Setup
-        */
-       private $setup;
-       
-       /**
-        * @var string
-        */
-       public $redirectUrl;
-       
-       /**
-        * @inheritDoc
-        */
-       public function readParameters() {
-               parent::readParameters();
-               
-               if (!empty($_GET['url']) && ApplicationHandler::getInstance()->isInternalURL($_GET['url'])) {
-                       $this->redirectUrl = $_GET['url'];
-               }
-               
-               if (WCF::getUser()->userID) {
-                       $this->performRedirect();
-               }
-               
-               $this->user = WCF::getSession()->getPendingUserChange();
-               if (!$this->user) {
-                       throw new PermissionDeniedException();
-               }
-               
-               $this->setups = Setup::getAllForUser($this->user);
-               
-               if (empty($this->setups)) {
-                       throw new \LogicException('Unreachable');
-               }
-               
-               \uasort($this->setups, function (Setup $a, Setup $b) {
-                       return $b->getObjectType()->priority <=> $a->getObjectType()->priority;
-               });
-               
-               $setupId = \array_keys($this->setups)[0];
-               if (isset($_GET['id'])) {
-                       $setupId = intval($_GET['id']);
-               }
-               
-               if (!isset($this->setups[$setupId])) {
-                       throw new IllegalLinkException();
-               }
-               
-               $this->setup = $this->setups[$setupId];
-               $this->method = $this->setup->getObjectType();
-               \assert($this->method->getDefinition()->definitionName === 'com.woltlab.wcf.multifactor');
-               
-               $this->processor = $this->method->getProcessor();
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       protected function createForm() {
-               parent::createForm();
-               
-               $this->processor->createAuthenticationForm($this->form, $this->setup);
-       }
-       
-       public function save() {
-               AbstractForm::save();
-               
-               WCF::getDB()->beginTransaction();
-               
-               $setup = $this->setup->lock();
-               
-               $this->returnData = $this->processor->processAuthenticationForm($this->form, $setup);
-               
-               WCF::getDB()->commitTransaction();
-               
-               WCF::getSession()->applyPendingUserChange($this->user);
-               
-               $this->saved();
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function saved() {
-               AbstractForm::saved();
-               
-               $this->performRedirect();
-       }
-       
-       /**
-        * Returns to the redirectUrl if given and to the landing page otherwise.
-        */
-       protected function performRedirect() {
-               if ($this->redirectUrl) {
-                       HeaderUtil::redirect($this->redirectUrl);
-               }
-               else {
-                       HeaderUtil::redirect(LinkHandler::getInstance()->getLink());
-               }
-               exit;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       protected function setFormAction() {
-               $this->form->action(LinkHandler::getInstance()->getControllerLink(static::class, [
-                       'object' => $this->setup,
-                       'url' => $this->redirectUrl,
-               ]));
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function assignVariables() {
-               parent::assignVariables();
-               
-               WCF::getTPL()->assign([
-                       'setups' => $this->setups,
-                       'user' => $this->user,
-                       'userProfile' => UserProfileRuntimeCache::getInstance()->getObject($this->user->userID),
-                       'setup' => $this->setup,
-                       'redirectUrl' => $this->redirectUrl,
-               ]);
-       }
+class MultifactorAuthenticationForm extends \wcf\form\MultifactorAuthenticationForm {
+
 }
index 5d16fa63e8651ac62d6d75d97e5d7eb86c320118..c01895450795f0b48fe8f094687a497ee6d2391b 100644 (file)
@@ -79,7 +79,7 @@ class MultifactorAuthenticationAbortForm extends AbstractForm {
                // never be accessed via a direct link.
                // If we reach it nonetheless we simply redirect back to the authentication
                // form which contains the proper button to perform the submission.
-               HeaderUtil::redirect(LinkHandler::getInstance()->getControllerLink(MultifactorAuthenticationForm::class));
+               HeaderUtil::redirect(LinkHandler::getInstance()->getLink('MultifactorAuthentication'));
                exit;
        }
 }