src/EventListener/JWTDecodedListener.php line 38

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: rostandnj
  5.  * Date: 15/3/19
  6.  * Time: 5:16 PM
  7.  */
  8. namespace App\EventListener;
  9. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Lexik\Bundle\JWTAuthenticationBundle\Exception\JWTFailureException;
  13. class JWTDecodedListener
  14. {
  15.     /**
  16.      * @var RequestStack
  17.      */
  18.     private $requestStack;
  19.     private $container;
  20.     /**
  21.      * @param RequestStack $requestStack
  22.      */
  23.     public function __construct(RequestStack $requestStack,ContainerInterface $c)
  24.     {
  25.         $this->requestStack $requestStack;
  26.         $this->container $c;
  27.     }
  28.     /**
  29.      * @param JWTDecodedEvent $event
  30.      *
  31.      * @return void
  32.      */
  33.     public function onJWTDecoded(JWTDecodedEvent $event)
  34.     {
  35.         $request $this->requestStack->getCurrentRequest();
  36.         $payload $event->getPayload();
  37.         $u=$this->container->get("user_manager")->getUserById($this->container->get("hash_service")->decrypt($payload['id']));
  38.         if($u === null$event->markAsInvalid();
  39.         if(is_string($u)) $event->markAsInvalid();
  40.         elseif ($u->getIsActive()==false$event->markAsInvalid();
  41.         elseif ($u->getIsClose()==true$event->markAsInvalid();
  42.     }
  43. }