Bladeren bron

fix the loginFailure deprecation

Olivier Massot 1 jaar geleden
bovenliggende
commit
2ad64e33bb

+ 11 - 0
ot_connect/Classes/Hooks/PostLoginFailureProcessingHook.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace Opentalent\OtConnect\Hooks;
+
+class PostLoginFailureProcessingHook
+{
+    public function postLoginFailureProcessing(...$params): void
+    {
+        setcookie("login_failed", "1", time()+3600, "/", "", 0);
+    }
+}

+ 3 - 0
ot_connect/ext_localconf.php

@@ -26,3 +26,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']['setup']['FE_alwaysAuthUser'] = tr
 
 // Use popup window to refresh login instead of the AJAX relogin:
 $GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] = 1;
+
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postLoginFailureProcessing'][] =
+    Opentalent\OtConnect\Hooks\PostLoginFailureProcessingHook::class;

+ 39 - 0
ot_core/Classes/Middleware/PostLoginFailureHandler.php

@@ -0,0 +1,39 @@
+<?php
+namespace Opentalent\OtCore\Middleware;
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use TYPO3\CMS\Core\Http\RedirectResponse;
+
+/**
+ * Check the existence of a 'login_failed' cookie and its value. If the cookie exists and if its value is
+ * true, store the information as a global variable: `$_SESSION['login_failed']`.
+ *
+ * @internal
+ */
+class PostLoginFailureHandler implements MiddlewareInterface
+{
+    public function __construct() {}
+
+    /**
+     *
+     * @param ServerRequestInterface $request
+     * @param RequestHandlerInterface $handler
+     * @return ResponseInterface
+     */
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+    {
+        if (isset($_COOKIE['login_failed'])) {
+            $_SESSION['login_failed'] = (bool)$_COOKIE['login_failed'];
+
+            // Remove cookie
+            unset($_COOKIE['login_failed']);
+            setcookie('login_failed', '', time() - 3600, '/');
+        }
+
+        // just pass the plate to the next middleware...
+        return $handler->handle($request);
+    }
+}

+ 1 - 1
ot_templating/Classes/ViewHelpers/LoginFailedViewHelper.php

@@ -33,7 +33,7 @@ class LoginFailedViewHelper extends OtAbstractViewHelper
         Closure $renderChildrenClosure,
         RenderingContextInterface $renderingContext
     ) {
-        $loginFailure = $GLOBALS['TSFE']->fe_user->loginFailure;
+        $loginFailure = $_SESSION['login_failed'] ?? false;
         if ($loginFailure) {
             return 1;
         }