Skip to content

Commit

Permalink
#7 Update to 6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
iMiMWeis committed Nov 23, 2023
1 parent 5441f8f commit 0a11ced
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
17 changes: 4 additions & 13 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="iMidiPasswordSite\Storefront\Controller\PasswordPageController" public="true">
<argument type="service" id="category.repository"/>
<argument type="service" id="Shopware\Storefront\Page\GenericPageLoader"/>
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
</service>
<service id="iMidiPasswordSite\Subscriber\CheckPasswordSubscriber">
<tag name="kernel.event_subscriber"/>
<argument type="service" id="router"/>
<argument type="service" id="category.repository"/>
<argument type="service" id="iMidiPasswordSite\Storefront\Controller\PasswordPageController"/>
</service>
<defaults autowire="true" autoconfigure="true" public="false">
</defaults>

<prototype namespace="iMidiPasswordSite\" resource="../../*"/>
</services>
</container>
1 change: 0 additions & 1 deletion src/Resources/views/storefront/page/restricted.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<div class="imidi-login-form">
{% block imidi_login_form %}
<form action="{{ path('frontend.password.login') }}" method="post">
{{ sw_csrf('frontend.password.login') }}
<input type="hidden" name="navigationId" value="{{ navigationId }}">
{% block imidi_login_form_inner %}

Expand Down
8 changes: 4 additions & 4 deletions src/Storefront/Controller/PasswordPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
26 changes: 14 additions & 12 deletions src/Subscriber/CheckPasswordSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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();
Expand All @@ -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());
Expand Down

0 comments on commit 0a11ced

Please sign in to comment.