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

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.     public static function getSubscribedEvents(): array
  43.     {
  44.         return [
  45.             FOSUserEvents::RESETTING_RESET_INITIALIZE => 'onResettingResetInitialize',
  46.             FOSUserEvents::RESETTING_RESET_SUCCESS => 'onResettingResetSuccess',
  47.         ];
  48.     }
  49.     public function onResettingResetInitialize(GetResponseUserEvent $event)
  50.     {
  51.         if (!$event->getUser()->isPasswordRequestNonExpired($this->tokenTtl)) {
  52.             $event->setResponse(new RedirectResponse($this->router->generate('fos_user_resetting_request')));
  53.         }
  54.     }
  55.     public function onResettingResetSuccess(FormEvent $event)
  56.     {
  57.         /** @var $user \FOS\UserBundle\Model\UserInterface */
  58.         $user $event->getForm()->getData();
  59.         $user->setConfirmationToken(null);
  60.         $user->setPasswordRequestedAt(null);
  61.         $user->setEnabled(true);
  62.     }
  63. }