Skip to content

Commit

Permalink
Merge pull request #19 from iMi-digital/develop
Browse files Browse the repository at this point in the history
#18 fix PasswordPageController to comply with SW Linter
  • Loading branch information
iMiMWeis authored Mar 8, 2024
2 parents 8695cfe + 198dc9c commit 6e1a1c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Service/PasswordPathService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(
{
}

// phpcs:ignore
public function checkPasswordInPath(CategoryEntity $category, PageLoadedEvent|HttpCacheHitEvent|CoreHttpCacheHitEvent $event)
{
$context = Context::createDefaultContext();
Expand Down Expand Up @@ -58,9 +59,12 @@ public function checkPasswordInPath(CategoryEntity $category, PageLoadedEvent|Ht
}
}

// phpcs:ignore
private function checkAuthenticated(PageLoadedEvent|HttpCacheHitEvent|CoreHttpCacheHitEvent $event, string $navigationId)
{
// phpcs:ignore
$session = $event->getRequest()->getSession();
// phpcs:ignore
$redirect = $event->getRequest()->server->get('REQUEST_URI');
$session->set('redirect', $redirect);

Expand All @@ -69,6 +73,7 @@ private function checkAuthenticated(PageLoadedEvent|HttpCacheHitEvent|CoreHttpCa
}
}

// phpcs:ignore
public function findNavigation(mixed $navigationId, PageLoadedEvent|HttpCacheHitEvent|CoreHttpCacheHitEvent $event)
{
$category = $this->categoryRepository->search(new Criteria([$navigationId]), Context::createDefaultContext())->first();
Expand Down
4 changes: 2 additions & 2 deletions src/Storefront/Controller/PasswordPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function showLogin(Request $request, SalesChannelContext $salesChannelCon
$page = $this->genericPageLoader->load($request, $salesChannelContext);

return $this->renderStorefront('@ImiDiPasswordProtectedPages/storefront/page/restricted.html.twig', [
'navigationId' => $request->get('navigationId'),
'navigationId' => $request->attributes->get('navigationId'),
'page' => $page,
]);
}
Expand All @@ -44,7 +44,7 @@ public function showLogin(Request $request, SalesChannelContext $salesChannelCon
*/
public function login(Request $request): Response
{
$navigationId = $request->get('navigationId');
$navigationId = $request->attributes->get('navigationId');

if(!$request->request->has('password')) {
$this->addFlash(self::DANGER, $this->trans('ImiDi.password-incorrect'));
Expand Down
4 changes: 4 additions & 0 deletions src/Subscriber/CheckPasswordSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function getSubscribedEvents(): array
return [
GenericPageLoadedEvent::class => 'onPageLoaded',
/** @deprecated tag:v6.6.0 - Delete HttpCacheHitEvent and use CoreHttpCacheHitEvent instead */
// phpcs:ignore
HttpCacheHitEvent::class => 'onCachedPageLoaded',
CoreHttpCacheHitEvent::class => 'onCachedPageLoaded',
KernelEvents::EXCEPTION => 'onException',
Expand All @@ -54,11 +55,14 @@ public function onPageLoaded(PageLoadedEvent $event)
$this->passwordPathService->checkPasswordInPath($activeNavigation, $event);
}

// phpcs:ignore
public function onCachedPageLoaded(HttpCacheHitEvent|CoreHttpCacheHitEvent $event)
{
if ($this->router instanceof RequestMatcherInterface) {
// phpcs:ignore
$parameters = $this->router->matchRequest($event->getRequest());
} else {
// phpcs:ignore
$parameters = $this->router->match($event->getRequest()->getPathInfo());
}

Expand Down

0 comments on commit 6e1a1c3

Please sign in to comment.