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
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 12 additions and 5 deletions

View File

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

View File

@ -11,14 +11,21 @@ class SessionAuthMiddleware extends BaseMiddleware
$route = $request->getAttribute('route');
$routeName = $route->getName();
$sessionService = new SessionService();
if ((!isset($_COOKIE['grocy_session']) || !$sessionService->IsValidSession($_COOKIE['grocy_session'])) && $routeName !== 'login')
if ($routeName === 'root')
{
$response = $response->withRedirect('/login');
$response = $next($request, $response);
}
else
{
$response = $next($request, $response);
$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;