Redis
This commit is contained in:
@ -1,26 +1,33 @@
|
||||
<?php
|
||||
namespace Incoviba\Middleware;
|
||||
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Incoviba\Service;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Authentication
|
||||
{
|
||||
public function __construct(protected ResponseFactoryInterface $responseFactory, protected Service\Login $service, protected string $login_url) {}
|
||||
public function __construct(
|
||||
protected ResponseFactoryInterface $responseFactory,
|
||||
protected Service\Login $service,
|
||||
protected LoggerInterface $logger,
|
||||
protected View $view,
|
||||
protected string $login_url) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if ($this->service->isIn() or $this->isValid($request)) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
$response = $this->responseFactory->createResponse(301, 'Not logged in');
|
||||
$uri = urlencode(base64_encode((string) $request->getUri()));
|
||||
return $response->withHeader('Location', implode('?', [$this->login_url, "url={$uri}"]))
|
||||
$this->logger->notice("Not logged in.");
|
||||
$response = $this->responseFactory->createResponse(301, 'Not logged in')
|
||||
->withHeader('Referer', (string) $request->getUri())
|
||||
->withHeader('X-Redirected-URI', (string) $request->getUri());
|
||||
return $this->view->render($response, 'login.form', ['redirect_uri' => (string) $request->getUri()]);
|
||||
}
|
||||
|
||||
protected function isValid(ServerRequestInterface $request): bool
|
||||
|
Reference in New Issue
Block a user