Fix session table missing on start with empty database

This commit is contained in:
Bernd Bestel
2018-04-15 14:49:00 +02:00
parent 5ddae116e0
commit e9bc51ca3d
2 changed files with 12 additions and 5 deletions

View File

@@ -43,7 +43,7 @@ if (!$applicationService->IsDemoInstallation())
} }
// Base route // Base route
$app->get('/', 'Grocy\Controllers\LoginController:Root'); $app->get('/', 'Grocy\Controllers\LoginController:Root')->setName('root');
// Login routes // Login routes
$app->get('/login', 'Grocy\Controllers\LoginController:LoginPage')->setName('login'); $app->get('/login', 'Grocy\Controllers\LoginController:LoginPage')->setName('login');

View File

@@ -11,6 +11,12 @@ class SessionAuthMiddleware extends BaseMiddleware
$route = $request->getAttribute('route'); $route = $request->getAttribute('route');
$routeName = $route->getName(); $routeName = $route->getName();
if ($routeName === 'root')
{
$response = $next($request, $response);
}
else
{
$sessionService = new SessionService(); $sessionService = new SessionService();
if ((!isset($_COOKIE['grocy_session']) || !$sessionService->IsValidSession($_COOKIE['grocy_session'])) && $routeName !== 'login') if ((!isset($_COOKIE['grocy_session']) || !$sessionService->IsValidSession($_COOKIE['grocy_session'])) && $routeName !== 'login')
{ {
@@ -20,6 +26,7 @@ class SessionAuthMiddleware extends BaseMiddleware
{ {
$response = $next($request, $response); $response = $next($request, $response);
} }
}
return $response; return $response;
} }