Files
grocy/middleware/SessionAuthMiddleware.php

39 lines
963 B
PHP
Raw Normal View History

2018-04-11 19:49:35 +02:00
<?php
2018-04-11 19:49:35 +02:00
namespace Grocy\Middleware;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Grocy\Services\SessionService;
2018-04-11 19:49:35 +02:00
class SessionAuthMiddleware extends AuthMiddleware
2018-04-11 19:49:35 +02:00
{
public function __construct(\DI\Container $container, ResponseFactoryInterface $responseFactory)
{
parent::__construct($container, $responseFactory);
$this->SessionCookieName = $this->AppContainer->get('LoginControllerInstance')->GetSessionCookieName();
}
protected $SessionCookieName;
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]);
}
}
2018-04-11 19:49:35 +02:00
}