mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
40 lines
964 B
PHP
40 lines
964 B
PHP
<?php
|
|
|
|
namespace Grocy\Middleware;
|
|
|
|
use Grocy\Services\SessionService;
|
|
use Psr\Http\Message\ResponseFactoryInterface;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
class SessionAuthMiddleware extends AuthMiddleware
|
|
{
|
|
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();
|
|
|
|
if (!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName]))
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return $sessionService->GetUserBySessionKey($_COOKIE[$this->SessionCookieName]);
|
|
}
|
|
|
|
}
|
|
|
|
}
|