Add MultifactorAuthenticationAbortForm
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 18 Nov 2020 11:15:30 +0000 (12:15 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 18 Nov 2020 13:13:17 +0000 (14:13 +0100)
wcfsetup/install/files/lib/form/MultifactorAuthenticationAbortForm.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/session/SessionHandler.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

diff --git a/wcfsetup/install/files/lib/form/MultifactorAuthenticationAbortForm.class.php b/wcfsetup/install/files/lib/form/MultifactorAuthenticationAbortForm.class.php
new file mode 100644 (file)
index 0000000..5d16fa6
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+namespace wcf\form;
+use wcf\system\exception\PermissionDeniedException;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+use wcf\util\HeaderUtil;
+
+/**
+ * Aborts the multi-factor authentication process.
+ *
+ * @author     Tim Duesterhus
+ * @copyright  2001-2020 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\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();
+       }
+       
+       /**
+        * Returns to the landing page otherwise.
+        */
+       protected function performRedirect() {
+               HeaderUtil::delayedRedirect(
+                       LinkHandler::getInstance()->getLink(),
+                       WCF::getLanguage()->getDynamicVariable('wcf.user.security.multifactor.authentication.logout.success')
+               );
+               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 f3d91112464f88751a6277ec204febb61eab7509..b63944f2a22c90c94bddae98e484c760768af443 100644 (file)
@@ -734,6 +734,13 @@ final class SessionHandler extends SingletonFactory {
                return $user;
        }
        
+       /**
+        * Clears a pending user change, reverses the effects of changeUserAfterMultifactor().
+        */
+       public function clearPendingUserChange(): void {
+               $this->unregister(self::CHANGE_USER_AFTER_MULTIFACTOR_KEY);
+       }
+       
        /**
         * Stores a new user object in this session, e.g. a user was guest because not
         * logged in, after the login his old session is used to store his full data.
index 481c29115ff151d815f0da11249a7638aa3e3cae..34b2e0f280b67baf90323eae84bc33d3f72cceae 100644 (file)
@@ -4892,6 +4892,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.security.multifactor.backup.code"><![CDATA[Notfall-Code]]></item>
                <item name="wcf.user.security.multifactor.backup.code.description"><![CDATA[Ein Notfall-Code besteht aus 20 Ziffern und ist nur einmal gültig.]]></item>
                <item name="wcf.user.security.multifactor.totp.deviceName.description.auth"><![CDATA[Das Gerät, das den genutzten Éinmalcode generiert hat.]]></item>
+               <item name="wcf.user.security.multifactor.authentication.logout.success"><![CDATA[Die Mehrfaktor-Authentifizierung wurde erfolgreich abgebrochen.]]></item>
        </category>
        <category name="wcf.user.trophy">
                <item name="wcf.user.trophy.trophyPoints"><![CDATA[Trophäen]]></item>
index 344f6e00209d0664c179bf68ae33510a1cf390c6..a3013bb10858ee94e7b5a13dbcb0713275938980 100644 (file)
@@ -4889,6 +4889,7 @@ Open the link below to access the user profile:
                <item name="wcf.user.security.multifactor.backup.code"><![CDATA[Emergency Code]]></item>
                <item name="wcf.user.security.multifactor.backup.code.description"><![CDATA[An emergency code consists of 20 digits and may only be used once.]]></item>
                <item name="wcf.user.security.multifactor.totp.deviceName.description.auth"><![CDATA[The device that generated the used one time code.]]></item>
+               <item name="wcf.user.security.multifactor.authentication.logout.success"><![CDATA[The multi-factor authentication has successfully been aborted.]]></item>
        </category>
        <category name="wcf.user.trophy">
                <item name="wcf.user.trophy.trophyPoints"><![CDATA[Trophies]]></item>