2019-09-18 00:31:59 +02:00
|
|
|
<?php
|
|
|
|
namespace App\Auth\Action;
|
|
|
|
|
|
|
|
use App\Auth\DatabaseAuth;
|
|
|
|
use Framework\Renderer\RendererInterface;
|
|
|
|
use Framework\Response\RedirectResponse;
|
|
|
|
use Framework\Session\FlashService;
|
2019-12-23 02:09:54 +01:00
|
|
|
use Framework\Session\SessionInterface;
|
2019-10-25 20:46:05 +02:00
|
|
|
use Psr\Container\ContainerInterface;
|
2019-09-18 00:31:59 +02:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
2019-10-25 20:46:05 +02:00
|
|
|
/**
|
|
|
|
* Class LogoutAction
|
|
|
|
* @package App\Auth\Action
|
|
|
|
*/
|
2019-09-18 00:31:59 +02:00
|
|
|
class LogoutAction
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var RendererInterface
|
|
|
|
*/
|
|
|
|
private $renderer;
|
|
|
|
/**
|
|
|
|
* @var DatabaseAuth
|
|
|
|
*/
|
|
|
|
private $auth;
|
|
|
|
/**
|
|
|
|
* @var FlashService
|
|
|
|
*/
|
|
|
|
private $flashService;
|
|
|
|
|
2019-10-25 20:46:05 +02:00
|
|
|
private $container;
|
|
|
|
|
|
|
|
public function __construct(RendererInterface $renderer, DatabaseAuth $auth, FlashService $flashService
|
2019-12-23 02:09:54 +01:00
|
|
|
, ContainerInterface $container, SessionInterface $session)
|
2019-09-18 00:31:59 +02:00
|
|
|
{
|
|
|
|
$this->renderer = $renderer;
|
|
|
|
$this->auth = $auth;
|
|
|
|
$this->flashService = $flashService;
|
2019-10-25 20:46:05 +02:00
|
|
|
$this->container = $container;
|
2019-12-23 02:09:54 +01:00
|
|
|
$this->session = $session;
|
2019-09-18 00:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __invoke(ServerRequestInterface $request)
|
|
|
|
{
|
2019-10-25 20:46:05 +02:00
|
|
|
$gmarchePrefix = $this->container->get('gmarche.prefix');
|
2019-12-02 22:49:12 +01:00
|
|
|
if(!isset($_SESSION)) {
|
2019-12-23 02:09:54 +01:00
|
|
|
//session_start();
|
2019-12-02 22:49:12 +01:00
|
|
|
}
|
2019-11-09 23:23:19 +01:00
|
|
|
unset($_SESSION['user']);
|
2019-12-23 02:09:54 +01:00
|
|
|
if ($this->session->get('username')) {
|
|
|
|
$this->session->delete('username');
|
|
|
|
}
|
2019-09-18 00:31:59 +02:00
|
|
|
$this->auth->logout();
|
|
|
|
$this->flashService->success('Vous êtes maintenant déconnecté');
|
2019-10-25 20:46:05 +02:00
|
|
|
return new RedirectResponse("$gmarchePrefix");
|
2019-09-18 00:31:59 +02:00
|
|
|
}
|
|
|
|
}
|