Add TReauthenticationCheck
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 1 Dec 2020 14:48:12 +0000 (15:48 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 7 Dec 2020 10:11:11 +0000 (11:11 +0100)
wcfsetup/install/files/lib/system/user/authentication/TReauthenticationCheck.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/user/authentication/TReauthenticationCheck.class.php b/wcfsetup/install/files/lib/system/user/authentication/TReauthenticationCheck.class.php
new file mode 100644 (file)
index 0000000..ef63bba
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+namespace wcf\system\user\authentication;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+use wcf\util\HeaderUtil;
+
+/**
+ * Provides a method to check for reauthentication and redirect otherwise.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2020 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\User\Authentication
+ * @since      5.4
+ */
+trait TReauthenticationCheck {
+       /**
+        * If the current user is in the need for a reauthentication a redirect to
+        * ReauthenticationForm is performed. After successful reauthentication the
+        * user will return to the URL given as `$returnTo`.
+        */
+       private function requestReauthentication(string $returnTo): void {
+               if (WCF::getSession()->needsReauthentication()) {
+                       HeaderUtil::redirect(
+                               LinkHandler::getInstance()->getLink('Reauthentication', [
+                                       'url' => $returnTo,
+                               ])
+                       );
+                       exit;
+               }
+       }
+}