vendor/bitbag/sylius-b2b-plugin/src/Organization/EventListener/ActiveUserAccountEventListener.php line 39

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file has been created by developers from BitBag.
  4.  * Feel free to contact us once you face any issues or want to start
  5.  * another great project.
  6.  * You can find more information about us on https://bitbag.io and write us
  7.  * an email on hello@bitbag.io.
  8.  */
  9. declare(strict_types=1);
  10. namespace BitBag\SyliusB2BPlugin\EventListener;
  11. use BitBag\SyliusB2BPlugin\Entity\ShopUserInterface;
  12. use Sylius\Bundle\UserBundle\Security\UserLoginInterface;
  13. use Sylius\Component\User\Repository\UserRepositoryInterface;
  14. use Symfony\Component\EventDispatcher\GenericEvent;
  15. use Webmozart\Assert\Assert;
  16. final class ActiveUserAccountEventListener
  17. {
  18.     private UserRepositoryInterface $userRepository;
  19.     private UserLoginInterface $userLogin;
  20.     private string $firewallContextName;
  21.     public function __construct(
  22.         UserRepositoryInterface $userRepository,
  23.         UserLoginInterface $userLogin,
  24.         string $firewallContextName,
  25.     ) {
  26.         $this->userRepository $userRepository;
  27.         $this->userLogin $userLogin;
  28.         $this->firewallContextName $firewallContextName;
  29.     }
  30.     public function onPasswordSet(GenericEvent $event): void
  31.     {
  32.         $user $event->getSubject();
  33.         Assert::isInstanceOf($userShopUserInterface::class);
  34.         $user->setEnabled(true);
  35.         $user->setEmailVerificationToken(null);
  36.         $user->setVerifiedAt(new \DateTime());
  37.         $user->setActivationToken(null);
  38.         $this->userRepository->add($user);
  39.         $this->userLogin->login($user$this->firewallContextName);
  40.     }
  41. }