From 09b23847b54dddf4070c5d584405d552cc0644a1 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 6 Jul 2019 18:29:18 +0200 Subject: [PATCH] Added a new `config.php` setting `DISABLE_AUTH` to be able to disable authentication / the login screen (closes #246) --- app.php | 9 +++++++++ changelog/50_2.4.3_2019-xx-xx.md | 1 + config-dist.php | 4 ++++ middleware/ApiKeyAuthMiddleware.php | 2 +- middleware/SessionAuthMiddleware.php | 2 +- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app.php b/app.php index df81207c..448058a8 100644 --- a/app.php +++ b/app.php @@ -40,6 +40,15 @@ require_once __DIR__ . '/vendor/autoload.php'; require_once GROCY_DATAPATH . '/config.php'; require_once __DIR__ . '/config-dist.php'; //For not in own config defined values we use the default ones +// Definitions for disabled authentication mode +if (GROCY_DISABLE_AUTH === true) +{ + if (!defined('GROCY_USER_ID')) + { + define('GROCY_USER_ID', 1); + } +} + // Setup base application $appContainer = new \Slim\Container([ 'settings' => [ diff --git a/changelog/50_2.4.3_2019-xx-xx.md b/changelog/50_2.4.3_2019-xx-xx.md index cdbb5024..ec8a8d11 100644 --- a/changelog/50_2.4.3_2019-xx-xx.md +++ b/changelog/50_2.4.3_2019-xx-xx.md @@ -9,3 +9,4 @@ - Items can now be switched between lists (there is a shopping list dropdown on the item edit page) - Items can now be marked as "done" (new check mark button per item, when clicked, the item will be displayed greyed out, when clicked again the item will be displayed normally again) - Improved that products can now also be consumed as spoiled from the stock overview page (option in the more/context menu per line) +- Added a new `config.php` setting `DISABLE_AUTH` to be able to disable authentication / the login screen diff --git a/config-dist.php b/config-dist.php index 2b3f2c4b..029da686 100644 --- a/config-dist.php +++ b/config-dist.php @@ -41,6 +41,10 @@ Setting('STOCK_BARCODE_LOOKUP_PLUGIN', 'DemoBarcodeLookupPlugin'); # set this to true Setting('DISABLE_URL_REWRITING', false); +# Set this to true if you want to disable authentication / the login screen, +# places where user context is needed will then use the default (first existing) user +Setting('DISABLE_AUTH', false); + diff --git a/middleware/ApiKeyAuthMiddleware.php b/middleware/ApiKeyAuthMiddleware.php index dd0bc62b..82487c03 100644 --- a/middleware/ApiKeyAuthMiddleware.php +++ b/middleware/ApiKeyAuthMiddleware.php @@ -22,7 +22,7 @@ class ApiKeyAuthMiddleware extends BaseMiddleware $route = $request->getAttribute('route'); $routeName = $route->getName(); - if (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL) + if (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL || GROCY_DISABLE_AUTH) { define('GROCY_AUTHENTICATED', true); $response = $next($request, $response); diff --git a/middleware/SessionAuthMiddleware.php b/middleware/SessionAuthMiddleware.php index df7c7a11..5cf436cc 100644 --- a/middleware/SessionAuthMiddleware.php +++ b/middleware/SessionAuthMiddleware.php @@ -25,7 +25,7 @@ class SessionAuthMiddleware extends BaseMiddleware { $response = $next($request, $response); } - elseif (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL) + elseif (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL || GROCY_DISABLE_AUTH) { $user = $sessionService->GetDefaultUser(); define('GROCY_AUTHENTICATED', true);