Reorganize project part 2

This commit is contained in:
Bernd Bestel
2018-04-11 19:49:35 +02:00
parent bcd5092427
commit 79b4bad014
54 changed files with 1985 additions and 826 deletions

View File

@@ -0,0 +1,32 @@
<?php
namespace Grocy\Middleware;
use Grocy\Services\SessionService;
class SessionMiddleware
{
public function __construct(\Slim\Container $container) {
$this->container = $container;
}
protected $container;
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next)
{
$route = $request->getAttribute('route');
$routeName = $route->getName();
$sessionService = new SessionService();
if ((!isset($_COOKIE['grocy_session']) || !$sessionService->IsValidSession($_COOKIE['grocy_session'])) && $routeName !== 'login')
{
$response = $response->withRedirect('/login');
}
else
{
$response = $next($request, $response);
}
return $response;
}
}