Revise session handling to prepare API authentication via token

This commit is contained in:
Bernd Bestel
2018-04-19 20:44:49 +02:00
parent 0c85342404
commit eae5b8bad9
9 changed files with 101 additions and 70 deletions

50
app.php
View File

@@ -3,46 +3,38 @@
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \Grocy\Middleware\SessionAuthMiddleware;
use \Grocy\Helpers\UrlManager;
use \Grocy\Services\ApplicationService;
use \Grocy\Controllers\LoginController;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/data/config.php';
// Setup base application
if (PHP_SAPI !== 'cli')
{
$appContainer = new \Slim\Container([
'settings' => [
'displayErrorDetails' => true,
'determineRouteBeforeAppMiddleware' => true
],
'view' => function($container)
{
return new \Slim\Views\Blade(__DIR__ . '/views', __DIR__ . '/data/viewcache');
},
'UrlManager' => function($container)
{
return new UrlManager(BASE_URL);
}
]);
$appContainer = new \Slim\Container([
'settings' => [
'displayErrorDetails' => true,
'determineRouteBeforeAppMiddleware' => true
],
'view' => function($container)
{
return new \Slim\Views\Blade(__DIR__ . '/views', __DIR__ . '/data/viewcache');
},
'LoginControllerInstance' => function($container)
{
return new LoginController($container, 'grocy_session');
},
'UrlManager' => function($container)
{
return new UrlManager(BASE_URL);
}
]);
$app = new \Slim\App($appContainer);
$app = new \Slim\App($appContainer);
}
else
if (PHP_SAPI === 'cli')
{
$app = new \Slim\App();
$app->add(\pavlakis\cli\CliRequest::class);
}
// Add session handling if this is not a demo installation
$applicationService = new ApplicationService();
if (!$applicationService->IsDemoInstallation())
{
$app->add(SessionAuthMiddleware::class);
}
require_once __DIR__ . '/routes.php';
$app->run();