vendor/ibexa/corporate-account/src/bundle/EventSubscriber/CorporatePortal/ChangePasswordSuccessViewSubscriber.php line 58

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\CorporateAccount\EventSubscriber\CorporatePortal;
  8. use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface;
  9. use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
  10. use Ibexa\CorporateAccount\Specification\IsCorporate;
  11. use Ibexa\User\View\ChangePassword\SuccessView;
  12. use JMS\TranslationBundle\Annotation\Desc;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\HttpKernel\Event\ViewEvent;
  16. use Symfony\Component\HttpKernel\KernelEvents;
  17. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  18. final class ChangePasswordSuccessViewSubscriber implements EventSubscriberInterface
  19. {
  20.     private UrlGeneratorInterface $urlGenerator;
  21.     private TranslatableNotificationHandlerInterface $notificationHandler;
  22.     private SiteAccessServiceInterface $siteAccessService;
  23.     public function __construct(
  24.         SiteAccessServiceInterface $siteAccessService,
  25.         UrlGeneratorInterface $urlGenerator,
  26.         TranslatableNotificationHandlerInterface $notificationHandler
  27.     ) {
  28.         $this->urlGenerator $urlGenerator;
  29.         $this->notificationHandler $notificationHandler;
  30.         $this->siteAccessService $siteAccessService;
  31.     }
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             KernelEvents::VIEW => ['onView'10],
  36.         ];
  37.     }
  38.     private function supports(ViewEvent $view): bool
  39.     {
  40.         $currentSiteAccess $this->siteAccessService->getCurrent();
  41.         if (!$currentSiteAccess) {
  42.             return false;
  43.         }
  44.         return $view->getControllerResult() instanceof SuccessView
  45.             && (new IsCorporate($this->siteAccessService))->isSatisfiedBy($currentSiteAccess);
  46.     }
  47.     public function onView(ViewEvent $view): void
  48.     {
  49.         if (!$this->supports($view)) {
  50.             return;
  51.         }
  52.         $this->notificationHandler->success(
  53.             /** @Desc("Your password has been successfully changed.") */
  54.             'ezplatform.change_password.success',
  55.             [],
  56.             'ibexa_change_password'
  57.         );
  58.         $view->setResponse(
  59.             new RedirectResponse(
  60.                 $this->urlGenerator->generate('ibexa.corporate_account.customer_portal.my_profile')
  61.             )
  62.         );
  63.     }
  64. }