aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-23 21:52:03 +0100
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit8e47af2b3620c920116ec056173277c039163ec1 (patch)
treed77f31f17bf4485f5a3ec0fea895205e9bde0554 /application
parentb0428aa9b02b058b72c40b6e8dc2298d55bf692f (diff)
downloadShaarli-8e47af2b3620c920116ec056173277c039163ec1.tar.gz
Shaarli-8e47af2b3620c920116ec056173277c039163ec1.tar.zst
Shaarli-8e47af2b3620c920116ec056173277c039163ec1.zip
Process logout through Slim controller
Diffstat (limited to 'application')
-rw-r--r--application/container/ContainerBuilder.php20
-rw-r--r--application/container/ShaarliContainer.php3
-rw-r--r--application/front/controllers/LogoutController.php31
3 files changed, 52 insertions, 2 deletions
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
index 99c12334..c5c4a2c3 100644
--- a/application/container/ContainerBuilder.php
+++ b/application/container/ContainerBuilder.php
@@ -11,6 +11,7 @@ use Shaarli\Formatter\FormatterFactory;
11use Shaarli\History; 11use Shaarli\History;
12use Shaarli\Plugin\PluginManager; 12use Shaarli\Plugin\PluginManager;
13use Shaarli\Render\PageBuilder; 13use Shaarli\Render\PageBuilder;
14use Shaarli\Render\PageCacheManager;
14use Shaarli\Security\LoginManager; 15use Shaarli\Security\LoginManager;
15use Shaarli\Security\SessionManager; 16use Shaarli\Security\SessionManager;
16 17
@@ -34,19 +35,30 @@ class ContainerBuilder
34 /** @var LoginManager */ 35 /** @var LoginManager */
35 protected $login; 36 protected $login;
36 37
37 public function __construct(ConfigManager $conf, SessionManager $session, LoginManager $login) 38 /** @var string */
38 { 39 protected $webPath;
40
41 public function __construct(
42 ConfigManager $conf,
43 SessionManager $session,
44 LoginManager $login,
45 string $webPath
46 ) {
39 $this->conf = $conf; 47 $this->conf = $conf;
40 $this->session = $session; 48 $this->session = $session;
41 $this->login = $login; 49 $this->login = $login;
50 $this->webPath = $webPath;
42 } 51 }
43 52
44 public function build(): ShaarliContainer 53 public function build(): ShaarliContainer
45 { 54 {
46 $container = new ShaarliContainer(); 55 $container = new ShaarliContainer();
56
47 $container['conf'] = $this->conf; 57 $container['conf'] = $this->conf;
48 $container['sessionManager'] = $this->session; 58 $container['sessionManager'] = $this->session;
49 $container['loginManager'] = $this->login; 59 $container['loginManager'] = $this->login;
60 $container['webPath'] = $this->webPath;
61
50 $container['plugins'] = function (ShaarliContainer $container): PluginManager { 62 $container['plugins'] = function (ShaarliContainer $container): PluginManager {
51 return new PluginManager($container->conf); 63 return new PluginManager($container->conf);
52 }; 64 };
@@ -81,6 +93,10 @@ class ContainerBuilder
81 return new FormatterFactory($container->conf, $container->loginManager->isLoggedIn()); 93 return new FormatterFactory($container->conf, $container->loginManager->isLoggedIn());
82 }; 94 };
83 95
96 $container['pageCacheManager'] = function (ShaarliContainer $container): PageCacheManager {
97 return new PageCacheManager($container->conf->get('resource.page_cache'));
98 };
99
84 return $container; 100 return $container;
85 } 101 }
86} 102}
diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php
index fdf2f77f..af62e574 100644
--- a/application/container/ShaarliContainer.php
+++ b/application/container/ShaarliContainer.php
@@ -10,6 +10,7 @@ use Shaarli\Formatter\FormatterFactory;
10use Shaarli\History; 10use Shaarli\History;
11use Shaarli\Plugin\PluginManager; 11use Shaarli\Plugin\PluginManager;
12use Shaarli\Render\PageBuilder; 12use Shaarli\Render\PageBuilder;
13use Shaarli\Render\PageCacheManager;
13use Shaarli\Security\LoginManager; 14use Shaarli\Security\LoginManager;
14use Shaarli\Security\SessionManager; 15use Shaarli\Security\SessionManager;
15use Slim\Container; 16use Slim\Container;
@@ -20,11 +21,13 @@ use Slim\Container;
20 * @property ConfigManager $conf 21 * @property ConfigManager $conf
21 * @property SessionManager $sessionManager 22 * @property SessionManager $sessionManager
22 * @property LoginManager $loginManager 23 * @property LoginManager $loginManager
24 * @property string $webPath
23 * @property History $history 25 * @property History $history
24 * @property BookmarkServiceInterface $bookmarkService 26 * @property BookmarkServiceInterface $bookmarkService
25 * @property PageBuilder $pageBuilder 27 * @property PageBuilder $pageBuilder
26 * @property PluginManager $pluginManager 28 * @property PluginManager $pluginManager
27 * @property FormatterFactory $formatterFactory 29 * @property FormatterFactory $formatterFactory
30 * @property PageCacheManager $pageCacheManager
28 */ 31 */
29class ShaarliContainer extends Container 32class ShaarliContainer extends Container
30{ 33{
diff --git a/application/front/controllers/LogoutController.php b/application/front/controllers/LogoutController.php
new file mode 100644
index 00000000..aba078c3
--- /dev/null
+++ b/application/front/controllers/LogoutController.php
@@ -0,0 +1,31 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller;
6
7use Shaarli\Security\LoginManager;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Class LogoutController
13 *
14 * Slim controller used to logout the user.
15 * It invalidates page cache and terminate the user session. Then it redirects to the homepage.
16 *
17 * @package Front\Controller
18 */
19class LogoutController extends ShaarliController
20{
21 public function index(Request $request, Response $response): Response
22 {
23 $this->container->pageCacheManager->invalidateCaches();
24 $this->container->sessionManager->logout();
25
26 // TODO: switch to a simple Cookie manager allowing to check the session, and create mocks.
27 setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->webPath);
28
29 return $response->withRedirect('./');
30 }
31}