4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
22 namespace Galette\Middleware
;
24 use Galette\Core\Login
;
25 use Galette\Core\Preferences
;
26 use Psr\Http\Message\ServerRequestInterface
as Request
;
27 use Psr\Http\Message\ResponseInterface
as Response
;
28 use Psr\Http\Server\RequestHandlerInterface
as RequestHandler
;
30 use Slim\Flash\Messages
;
31 use Slim\Routing\RouteParser
;
34 * Galette Slim middleware for public pages access
36 * @author Johan Cwiklinski <johan@x-tnd.be>
43 protected Messages
$flash;
53 private RouteParser
$routeparser;
58 private Preferences
$preferences;
63 * @param Container $container Container instance
65 public function __construct(Container
$container)
67 $this->login
= $container->get('login');
68 $this->flash
= $container->get('flash');
69 $this->routeparser
= $container->get(RouteParser
::class);
70 $this->preferences
= $container->get('preferences');
74 * Middleware invokable class
76 * @param Request $request PSR7 request
77 * @param RequestHandler $handler PSR7 request handler
81 public function __invoke(Request
$request, RequestHandler
$handler): Response
83 $response = new \Slim\Psr7\
Response();
85 if (!$this->preferences
->showPublicPages($this->login
)) {
86 $this->flash
->addMessage('error_detected', _T("Unauthorized"));
90 $this->routeparser
->urlFor('slash')
94 return $handler->handle($request);