vendor/nucleos/user-bundle/src/EventListener/AuthenticationListener.php line 43

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the NucleosUserBundle package.
  5.  *
  6.  * (c) Christian Gripp <mail@core23.de>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Nucleos\UserBundle\EventListener;
  12. use Nucleos\UserBundle\Event\FilterUserResponseEvent;
  13. use Nucleos\UserBundle\Event\UserEvent;
  14. use Nucleos\UserBundle\NucleosUserEvents;
  15. use Nucleos\UserBundle\Security\LoginManager;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. use Symfony\Component\Security\Core\Exception\AccountStatusException;
  18. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  19. final class AuthenticationListener implements EventSubscriberInterface
  20. {
  21.     private LoginManager $loginManager;
  22.     private string $firewallName;
  23.     public function __construct(LoginManager $loginManagerstring $firewallName)
  24.     {
  25.         $this->loginManager $loginManager;
  26.         $this->firewallName $firewallName;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             NucleosUserEvents::RESETTING_RESET_COMPLETED => 'authenticate',
  32.         ];
  33.     }
  34.     public function authenticate(FilterUserResponseEvent $eventstring $eventNameEventDispatcherInterface $eventDispatcher): void
  35.     {
  36.         try {
  37.             $this->loginManager->logInUser($this->firewallName$event->getUser(), $event->getResponse());
  38.             $eventDispatcher->dispatch(new UserEvent($event->getUser(), $event->getRequest()), NucleosUserEvents::SECURITY_IMPLICIT_LOGIN);
  39.         } catch (AccountStatusException $ex) {
  40.             // We simply do not authenticate users which do not pass the user
  41.             // checker (not enabled, expired, etc.).
  42.         }
  43.     }
  44. }