vendor/friendsofsymfony/user-bundle/EventListener/ResettingListener.php line 67

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSUserBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\UserBundle\EventListener;
  11. use FOS\UserBundle\Event\FormEvent;
  12. use FOS\UserBundle\Event\GetResponseUserEvent;
  13. use FOS\UserBundle\FOSUserEvents;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\HttpFoundation\RedirectResponse;
  16. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  17. /**
  18.  * @internal
  19.  *
  20.  * @final
  21.  */
  22. class ResettingListener implements EventSubscriberInterface
  23. {
  24.     /**
  25.      * @var UrlGeneratorInterface
  26.      */
  27.     private $router;
  28.     /**
  29.      * @var int
  30.      */
  31.     private $tokenTtl;
  32.     /**
  33.      * ResettingListener constructor.
  34.      *
  35.      * @param int $tokenTtl
  36.      */
  37.     public function __construct(UrlGeneratorInterface $router$tokenTtl)
  38.     {
  39.         $this->router $router;
  40.         $this->tokenTtl $tokenTtl;
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             FOSUserEvents::RESETTING_RESET_INITIALIZE => 'onResettingResetInitialize',
  49.             FOSUserEvents::RESETTING_RESET_SUCCESS => 'onResettingResetSuccess',
  50.         ];
  51.     }
  52.     public function onResettingResetInitialize(GetResponseUserEvent $event)
  53.     {
  54.         if (!$event->getUser()->isPasswordRequestNonExpired($this->tokenTtl)) {
  55.             $event->setResponse(new RedirectResponse($this->router->generate('fos_user_resetting_request')));
  56.         }
  57.     }
  58.     public function onResettingResetSuccess(FormEvent $event)
  59.     {
  60.         /** @var $user \FOS\UserBundle\Model\UserInterface */
  61.         $user $event->getForm()->getData();
  62.         $user->setConfirmationToken(null);
  63.         $user->setPasswordRequestedAt(null);
  64.         $user->setEnabled(true);
  65.     }
  66. }