diff --git a/composer.json b/composer.json index ffa4cb1..3364a2b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "imi/shopware6-password-site", - "version": "1.1.0", + "version": "1.2.0", "description": "iMi Password Protected Page", "type": "shopware-platform-plugin", "license": "AGPL-3.0-or-later", @@ -16,8 +16,8 @@ } ], "require": { - "php": "^7.4 || ^8.0", - "shopware/core": "~v6.4.13" + "php": "^8.0", + "shopware/core": "^6.5" }, "extra": { "shopware-plugin-class": "iMidiPasswordSite\\iMidiPasswordSite", diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 3f0d8fb..bbbef14 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -5,18 +5,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - - - - - - - - - - - + + + + diff --git a/src/Resources/views/storefront/page/restricted.html.twig b/src/Resources/views/storefront/page/restricted.html.twig index 0826e74..eae7710 100644 --- a/src/Resources/views/storefront/page/restricted.html.twig +++ b/src/Resources/views/storefront/page/restricted.html.twig @@ -5,7 +5,6 @@
{% block imidi_login_form %}
- {{ sw_csrf('frontend.password.login') }} {% block imidi_login_form_inner %} diff --git a/src/Storefront/Controller/PasswordPageController.php b/src/Storefront/Controller/PasswordPageController.php index b234e11..be6ae99 100644 --- a/src/Storefront/Controller/PasswordPageController.php +++ b/src/Storefront/Controller/PasswordPageController.php @@ -18,12 +18,12 @@ */ class PasswordPageController extends StorefrontController { - private EntityRepository $categoryRepositoryInterface; + private EntityRepository $categoryRepository; private GenericPageLoader $genericPageLoader; - public function __construct(EntityRepository $categoryRepositoryInterface, GenericPageLoader $genericPageLoader) + public function __construct(EntityRepository $categoryRepository, GenericPageLoader $genericPageLoader) { - $this->categoryRepositoryInterface = $categoryRepositoryInterface; + $this->categoryRepository = $categoryRepository; $this->genericPageLoader = $genericPageLoader; } @@ -77,7 +77,7 @@ public function getCategoryPassword(string $navigationId, Context $context): ?st return null; } - $result = $this->categoryRepositoryInterface->search(new Criteria([$navigationId]), $context); + $result = $this->categoryRepository->search(new Criteria([$navigationId]), $context); if ($result->count() <= 0) { return null; } diff --git a/src/Subscriber/CheckPasswordSubscriber.php b/src/Subscriber/CheckPasswordSubscriber.php index 09248c5..79c17dd 100644 --- a/src/Subscriber/CheckPasswordSubscriber.php +++ b/src/Subscriber/CheckPasswordSubscriber.php @@ -8,6 +8,7 @@ use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Storefront\Framework\Cache\Event\HttpCacheHitEvent; +use Shopware\Storefront\Framework\Routing\Router; use Shopware\Storefront\Page\GenericPageLoadedEvent; use Shopware\Storefront\Page\PageLoadedEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -16,16 +17,17 @@ class CheckPasswordSubscriber implements EventSubscriberInterface { const AUTH_SESSION_PREFIX = 'auth_'; - private $matcher; - private $categoryRepositoryInterface; + private $router; + private $categoryRepository; private $passwordPageController; - public function __construct($matcher, - EntityRepository $categoryRepositoryInterface, + public function __construct( + Router $router, + EntityRepository $categoryRepository, PasswordPageController $passwordPageController) { - $this->matcher = $matcher; - $this->categoryRepositoryInterface = $categoryRepositoryInterface; + $this->router = $router; + $this->categoryRepository = $categoryRepository; $this->passwordPageController = $passwordPageController; } @@ -57,15 +59,15 @@ public function onCachedPageLoaded(HttpCacheHitEvent $event) { $requestUri = $event->getRequest()->attributes->get('resolved-uri'); - if ($this->matcher instanceof RequestMatcherInterface) { - $parameters = $this->matcher->matchRequest($event->getRequest()); + if ($this->router instanceof RequestMatcherInterface) { + $parameters = $this->router->matchRequest($event->getRequest()); } else { - $parameters = $this->matcher->match($event->getRequest()->getPathInfo()); + $parameters = $this->router->match($event->getRequest()->getPathInfo()); } if ($parameters['_route'] === 'frontend.navigation.page') { $navigationId = $parameters['navigationId']; - $category = $this->categoryRepositoryInterface->search(new Criteria([$navigationId]), Context::createDefaultContext())->first(); + $category = $this->categoryRepository->search(new Criteria([$navigationId]), Context::createDefaultContext())->first(); $this->checkPasswordInPath($category, $event); } } @@ -82,7 +84,7 @@ private function checkAuthenticated($event, string $navigationId) private function checkPasswordInPath(CategoryEntity $category, $event) { - //include matcher + //include router $context = Context::createDefaultContext(); if ($event instanceof PageLoadedEvent) { $context = $event->getContext(); @@ -99,7 +101,7 @@ private function checkPasswordInPath(CategoryEntity $category, $event) $path .= $category->getId(); $parents = array_reverse(array_slice(explode('|', $path), 1)); foreach ($parents as $parentId) { - $parent = $this->categoryRepositoryInterface + $parent = $this->categoryRepository ->search(new Criteria([$parentId]), $context)->first(); if ($parent->getCustomFields() !== null && array_key_exists('password_site_password', $parent->getCustomFields())) { $this->checkAuthenticated($event, $parent->getId());