src/Controller/UserBundle/Controller/RegistrationController.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\Controller\UserBundle\Controller;
  3. use App\Form\Type\ContactFormType;
  4. use App\Repository\HearingBrandRepository;
  5. use FOS\UserBundle\Controller\RegistrationController as BaseRegistrationController;
  6. use FOS\UserBundle\Event\FormEvent;
  7. use FOS\UserBundle\FOSUserEvents;
  8. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use FOS\UserBundle\Form\Factory\FactoryInterface;
  13. use FOS\UserBundle\Model\UserManagerInterface;
  14. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  15. class RegistrationController extends BaseRegistrationController
  16. {
  17.     private HearingBrandRepository $hearingBrandRepository;
  18.     private EventDispatcherInterface $eventDispatcher;
  19.     private FactoryInterface $formFactory;
  20.     private UserManagerInterface $userManager;
  21.     private TokenStorageInterface $tokenStorage;
  22.     public function __construct(EventDispatcherInterface $eventDispatcherFactoryInterface $formFactoryUserManagerInterface $userManagerTokenStorageInterface $tokenStoragehearingBrandRepository $hearingBrandRepository)
  23.     {
  24.         parent::__construct($eventDispatcher$formFactory$userManager$tokenStorage);
  25.         $this->eventDispatcher $eventDispatcher;
  26.         $this->formFactory     $formFactory;
  27.         $this->userManager     $userManager;
  28.         $this->tokenStorage    $tokenStorage;
  29.         $this->hearingBrandRepository $hearingBrandRepository;
  30.     }
  31.     /**
  32.      * @Route("/register", name="fos_user_registration_register")
  33.      */
  34.     public function register(Request $requestEventDispatcherInterface $eventDispatcher): Response
  35.     {
  36.         $user $this->userManager->createUser();
  37.         $user->setEnabled(true);
  38.         $form $this->formFactory->createForm();
  39.         $form->setData($user);
  40.         $form->handleRequest($request);
  41.         if ($form->isSubmitted() && $form->isValid()) {
  42.             $event = new FormEvent($form$request);
  43.             $eventDispatcher->dispatch($eventFOSUserEvents::REGISTRATION_SUCCESS);
  44.             $this->userManager->updateUser($user);
  45.             return $this->redirectToRoute('fos_user_registration_confirmed');
  46.         }
  47.         $contactForm $this->createForm(ContactFormType::class, null, [
  48.             'method' => 'POST'
  49.         ]);
  50.         return $this->render('front_v4/mca/landing_page/freelancer/lp_freelancer.html.twig', [
  51.             'contactForm' => $contactForm->createView(),
  52.             'form' => $form->createView(),
  53.             'hearingBrands' => $this->hearingBrandRepository->findAll()
  54.         ]);
  55.     }
  56. }