Optimize and refactor latest changes

This commit is contained in:
Bernd Bestel
2018-07-25 19:28:15 +02:00
parent 4685ff4145
commit 42c1709633
33 changed files with 315 additions and 254 deletions

View File

@@ -19,23 +19,23 @@ class SessionAuthMiddleware extends BaseMiddleware
{
$route = $request->getAttribute('route');
$routeName = $route->getName();
$sessionService = new SessionService();
if ($routeName === 'root' || $this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation())
if ($routeName === 'root')
{
if ($this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation())
{
define('GROCY_AUTHENTICATED', true);
$localizationService = new LocalizationService(GROCY_CULTURE);
define('GROCY_USER_USERNAME', $localizationService->Localize('Demo User'));
define('GROCY_USER_ID', -1);
}
$response = $next($request, $response);
}
elseif (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL)
{
$user = $sessionService->GetDefaultUser();
define('GROCY_AUTHENTICATED', true);
define('GROCY_USER_USERNAME', $user->username);
define('GROCY_USER_ID', $user->id);
$response = $next($request, $response);
}
else
{
$sessionService = new SessionService();
if ((!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName])) && $routeName !== 'login')
{
define('GROCY_AUTHENTICATED', false);