Files
grocy/middleware/SessionAuthMiddleware.php

40 lines
964 B
PHP
Raw Normal View History

2018-04-11 19:49:35 +02:00
<?php
namespace Grocy\Middleware;
2020-08-31 20:40:31 +02:00
use Grocy\Services\SessionService;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
class SessionAuthMiddleware extends AuthMiddleware
2018-04-11 19:49:35 +02:00
{
2020-08-31 20:40:31 +02:00
protected $SessionCookieName;
public function __construct(\DI\Container $container, ResponseFactoryInterface $responseFactory)
{
parent::__construct($container, $responseFactory);
$this->SessionCookieName = $this->AppContainer->get('LoginControllerInstance')->GetSessionCookieName();
}
function authenticate(Request $request)
{
if (!defined('GROCY_SHOW_AUTH_VIEWS'))
{
define('GROCY_SHOW_AUTH_VIEWS', true);
}
$sessionService = SessionService::getInstance();
2020-08-31 20:40:31 +02:00
if (!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName]))
{
return null;
}
else
{
return $sessionService->GetUserBySessionKey($_COOKIE[$this->SessionCookieName]);
}
2020-08-31 20:40:31 +02:00
}
2020-08-31 20:40:31 +02:00
2018-04-11 19:49:35 +02:00
}