<?php
namespace App\Controller\UserBundle\Controller;
use App\Form\Type\ContactFormType;
use App\Repository\HearingBrandRepository;
use FOS\UserBundle\Controller\RegistrationController as BaseRegistrationController;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use FOS\UserBundle\Form\Factory\FactoryInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class RegistrationController extends BaseRegistrationController
{
private HearingBrandRepository $hearingBrandRepository;
private EventDispatcherInterface $eventDispatcher;
private FactoryInterface $formFactory;
private UserManagerInterface $userManager;
private TokenStorageInterface $tokenStorage;
public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenStorageInterface $tokenStorage, hearingBrandRepository $hearingBrandRepository)
{
parent::__construct($eventDispatcher, $formFactory, $userManager, $tokenStorage);
$this->eventDispatcher = $eventDispatcher;
$this->formFactory = $formFactory;
$this->userManager = $userManager;
$this->tokenStorage = $tokenStorage;
$this->hearingBrandRepository = $hearingBrandRepository;
}
/**
* @Route("/register", name="fos_user_registration_register")
*/
public function register(Request $request, EventDispatcherInterface $eventDispatcher): Response
{
$user = $this->userManager->createUser();
$user->setEnabled(true);
$form = $this->formFactory->createForm();
$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$event = new FormEvent($form, $request);
$eventDispatcher->dispatch($event, FOSUserEvents::REGISTRATION_SUCCESS);
$this->userManager->updateUser($user);
return $this->redirectToRoute('fos_user_registration_confirmed');
}
$contactForm = $this->createForm(ContactFormType::class, null, [
'method' => 'POST'
]);
return $this->render('front_v4/mca/landing_page/freelancer/lp_freelancer.html.twig', [
'contactForm' => $contactForm->createView(),
'form' => $form->createView(),
'hearingBrands' => $this->hearingBrandRepository->findAll()
]);
}
}