Replace the single user (defined in /data/config.php) with a multi user management thing

This commit is contained in:
Bernd Bestel
2018-07-24 19:31:43 +02:00
parent b52ab91606
commit 7f8540ff4e
19 changed files with 695 additions and 23 deletions

View File

@@ -3,6 +3,7 @@
namespace Grocy\Middleware;
use \Grocy\Services\SessionService;
use \Grocy\Services\LocalizationService;
class SessionAuthMiddleware extends BaseMiddleware
{
@@ -21,7 +22,15 @@ class SessionAuthMiddleware extends BaseMiddleware
if ($routeName === 'root' || $this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation())
{
define('AUTHENTICATED', $this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation());
if ($this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation())
{
define('AUTHENTICATED', true);
$localizationService = new LocalizationService(CULTURE);
define('GROCY_USER_USERNAME', $localizationService->Localize('Demo User'));
define('GROCY_USER_ID', -1);
}
$response = $next($request, $response);
}
else
@@ -34,7 +43,18 @@ class SessionAuthMiddleware extends BaseMiddleware
}
else
{
define('AUTHENTICATED', $routeName !== 'login');
if ($routeName !== 'login')
{
$user = $sessionService->GetUserBySessionKey($_COOKIE[$this->SessionCookieName]);
define('AUTHENTICATED', true);
define('GROCY_USER_USERNAME', $user->username);
define('GROCY_USER_ID', $user->id);
}
else
{
define('AUTHENTICATED', false);
}
$response = $next($request, $response);
}
}