aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controllers/LogoutController.php
blob: aba078c33d20b0df4902baa3c45c229bbda61af7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

declare(strict_types=1);

namespace Shaarli\Front\Controller;

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.
 *
 * @package Front\Controller
 */
class LogoutController extends ShaarliController
{
    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('./');
    }
}