]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/front/controller/admin/LogoutController.php
Initialize admin Slim controllers
[github/shaarli/Shaarli.git] / application / front / controller / admin / LogoutController.php
diff --git a/application/front/controller/admin/LogoutController.php b/application/front/controller/admin/LogoutController.php
new file mode 100644 (file)
index 0000000..41e8198
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Shaarli\Front\Controller\Admin;
+
+use Shaarli\Security\LoginManager;
+use Slim\Http\Request;
+use Slim\Http\Response;
+
+/**
+ * Class LogoutController
+ *
+ * Slim controller used to logout the user.
+ * It invalidates page cache and terminate the user session. Then it redirects to the homepage.
+ */
+class LogoutController extends ShaarliAdminController
+{
+    public function index(Request $request, Response $response): Response
+    {
+        $this->container->pageCacheManager->invalidateCaches();
+        $this->container->sessionManager->logout();
+
+        // TODO: switch to a simple Cookie manager allowing to check the session, and create mocks.
+        setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->webPath);
+
+        return $response->withRedirect('./');
+    }
+}