Explorar o código

add the url redirection after logout

Olivier Massot %!s(int64=5) %!d(string=hai) anos
pai
achega
e6477e1873

+ 41 - 0
ot_templating/Classes/Middleware/RequestHandler.php

@@ -0,0 +1,41 @@
+<?php
+namespace Opentalent\OtTemplating\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;
+
+/**
+ * Hooks into the frontend request and process the request
+ *
+ * @internal
+ */
+class RequestHandler implements MiddlewareInterface
+{
+    /**
+     *
+     * @param ServerRequestInterface $request
+     * @param RequestHandlerInterface $handler
+     * @return ResponseInterface
+     */
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+    {
+        $uri = $request->getUri();
+        if (preg_match("/^(.*&)*logintype=logout(&.*)*$/", $uri->getQuery())) {
+            // this is a logout request, and it has already been handled by the
+            // auth service.
+            $newQuery = preg_replace("/logintype=logout&?/", '', $uri->getQuery());
+
+            return new RedirectResponse(
+                $uri->withQuery($newQuery),
+                303,
+                ['X-Redirect-By' => 'OtTemplating logout redirection']
+            );
+        }
+
+        // just pass the plate to the next middleware...
+        return $handler->handle($request);
+    }
+}

+ 18 - 0
ot_templating/Configuration/RequestMiddlewares.php

@@ -0,0 +1,18 @@
+<?php
+
+/**
+ * Register middlewares, which will be triggered at each request
+ */
+return [
+    'frontend' => [
+        'ottemplating-errorhandler' => [
+            'target' => Opentalent\OtTemplating\Middleware\RequestHandler::class,
+            'before' => [
+                'typo3/cms-adminpanel/data-persister'
+            ],
+            'after' => [
+                'typo3/cms-adminpanel/renderer'
+            ],
+        ],
+    ],
+];