diff --git a/src/Controller/RedirectController.php b/src/Controller/RedirectController.php index 3d60bea8..022c1286 100644 --- a/src/Controller/RedirectController.php +++ b/src/Controller/RedirectController.php @@ -28,20 +28,17 @@ use function in_array; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Contracts\Translation\TranslatorInterface; class RedirectController extends AbstractController { protected string $default_locale; protected TranslatorInterface $translator; - protected SessionInterface $session; protected bool $enforce_index_php; - public function __construct(string $default_locale, TranslatorInterface $translator, SessionInterface $session, bool $enforce_index_php) + public function __construct(string $default_locale, TranslatorInterface $translator, bool $enforce_index_php) { $this->default_locale = $default_locale; - $this->session = $session; $this->translator = $translator; $this->enforce_index_php = $enforce_index_php; } diff --git a/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php b/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php index 5e18826b..7b816d5e 100644 --- a/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php +++ b/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php @@ -26,6 +26,7 @@ use App\Entity\LogSystem\UserLoginLogEntry; use App\Entity\UserSystem\User; use App\Services\LogSystem\EventLogger; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -39,15 +40,15 @@ use Symfony\Contracts\Translation\TranslatorInterface; final class LoginSuccessSubscriber implements EventSubscriberInterface { private TranslatorInterface $translator; - private FlashBagInterface $flashBag; + private RequestStack $requestStack; private EventLogger $eventLogger; private bool $gpdr_compliance; - public function __construct(TranslatorInterface $translator, SessionInterface $session, EventLogger $eventLogger, bool $gpdr_compliance) + public function __construct(TranslatorInterface $translator, RequestStack $requestStack, EventLogger $eventLogger, bool $gpdr_compliance) { /** @var Session $session */ $this->translator = $translator; - $this->flashBag = $session->getFlashBag(); + $this->requestStack = $requestStack; $this->eventLogger = $eventLogger; $this->gpdr_compliance = $gpdr_compliance; } @@ -62,8 +63,11 @@ final class LoginSuccessSubscriber implements EventSubscriberInterface $this->eventLogger->logAndFlush($log); } + /** @var Session $session */ + $session = $this->requestStack->getSession(); + $flashBag = $session->getFlashBag(); - $this->flashBag->add('notice', $this->translator->trans('flash.login_successful')); + $flashBag->add('notice', $this->translator->trans('flash.login_successful')); } /** diff --git a/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php b/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php index 98020f03..11c081b4 100644 --- a/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php +++ b/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php @@ -56,14 +56,11 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface */ public const REDIRECT_TARGET = 'user_settings'; private Security $security; - private FlashBagInterface $flashBag; private HttpUtils $httpUtils; - public function __construct(Security $security, SessionInterface $session, HttpUtils $httpUtils) + public function __construct(Security $security, HttpUtils $httpUtils) { - /** @var Session $session */ $this->security = $security; - $this->flashBag = $session->getFlashBag(); $this->httpUtils = $httpUtils; } @@ -103,9 +100,13 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface return; } + /** @var Session $session */ + $session = $request->getSession(); + $flashBag = $session->getFlashBag(); + //Show appropriate message to user about the reason he was redirected if ($user->isNeedPwChange()) { - $this->flashBag->add('warning', 'user.pw_change_needed.flash'); + $flashBag->add('warning', 'user.pw_change_needed.flash'); } if (static::TFARedirectNeeded($user)) { diff --git a/src/EventSubscriber/UserSystem/UpgradePermissionsSchemaSubscriber.php b/src/EventSubscriber/UserSystem/UpgradePermissionsSchemaSubscriber.php index 6fddea0a..a7392615 100644 --- a/src/EventSubscriber/UserSystem/UpgradePermissionsSchemaSubscriber.php +++ b/src/EventSubscriber/UserSystem/UpgradePermissionsSchemaSubscriber.php @@ -40,16 +40,14 @@ class UpgradePermissionsSchemaSubscriber implements EventSubscriberInterface private Security $security; private PermissionSchemaUpdater $permissionSchemaUpdater; private EntityManagerInterface $entityManager; - private FlashBagInterface $flashBag; private EventCommentHelper $eventCommentHelper; - public function __construct(Security $security, PermissionSchemaUpdater $permissionSchemaUpdater, EntityManagerInterface $entityManager, SessionInterface $session, EventCommentHelper $eventCommentHelper) + public function __construct(Security $security, PermissionSchemaUpdater $permissionSchemaUpdater, EntityManagerInterface $entityManager, EventCommentHelper $eventCommentHelper) { /** @var Session $session */ $this->security = $security; $this->permissionSchemaUpdater = $permissionSchemaUpdater; $this->entityManager = $entityManager; - $this->flashBag = $session->getFlashBag(); $this->eventCommentHelper = $eventCommentHelper; } @@ -65,11 +63,15 @@ class UpgradePermissionsSchemaSubscriber implements EventSubscriberInterface $user = $this->entityManager->getRepository(User::class)->getAnonymousUser(); } + /** @var Session $session */ + $session = $event->getRequest()->getSession(); + $flashBag = $session->getFlashBag(); + if ($this->permissionSchemaUpdater->isSchemaUpdateNeeded($user)) { $this->eventCommentHelper->setMessage('Automatic permission schema update'); $this->permissionSchemaUpdater->userUpgradeSchemaRecursively($user); $this->entityManager->flush(); - $this->flashBag->add('notice', 'user.permissions_schema_updated'); + $flashBag->add('notice', 'user.permissions_schema_updated'); } }