src/UserRegistration/Controller/UserRegistrationController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\UserRegistration\Controller;
  3. use App\Controller\AbstractController;
  4. use App\UserRegistration\Form\LawFirmCreateFormType;
  5. use App\UserRegistration\Repository\UserRegistrationRepository;
  6. use AppBundle\Enum\LanguageEnum;
  7. use AppBundle\Enum\LawFirmEquipmentEnum;
  8. use AppBundle\Enum\LawFirmOrganizationEnum;
  9. use AppBundle\Enum\UserJobTitleEnum;
  10. use Exception;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  16. use Symfony\Component\Intl\Countries;
  17. use Symfony\Component\Intl\Currencies;
  18. /**
  19.  * class UserRegistrationController
  20.  * @Route("/registration", name="registration_")
  21.  */
  22. class UserRegistrationController extends AbstractController
  23. {
  24.     /**
  25.      * @Route("", name="user_create_form")
  26.      * @param CsrfTokenManagerInterface $tokenManager
  27.      * @return Response
  28.      */
  29.     public function index(CsrfTokenManagerInterface $tokenManager): Response
  30.     {
  31.         $formToken $tokenManager
  32.             ->getToken('user_create_form')
  33.             ->getValue();
  34.         return $this->render('registration/register_step_one.html.twig', [
  35.             'formToken' => $formToken,
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/confirmation", name="confirm", options={"expose"=true})
  40.      * @return Response
  41.      */
  42.     public function userRegistrationConfirmation(): Response
  43.     {
  44.         return $this->render('registration/confirmation.html.twig');
  45.     }
  46.     /**
  47.      * @Route("/end-registration/{userToken}", name="end_registration", options={"expose"=true})
  48.      * @param Request $request
  49.      * @param CsrfTokenManagerInterface $tokenManager
  50.      * @param UserRegistrationRepository $repository
  51.      * @param LoggerInterface $logger
  52.      * @return Response
  53.      */
  54.     public function userRegistrationEnd(
  55.         Request $request,
  56.         CsrfTokenManagerInterface $tokenManager,
  57.         UserRegistrationRepository $repository,
  58.         LoggerInterface $logger
  59.     ): Response {
  60.         try {
  61.             $userToken $request->get('userToken');
  62.             $userRegistration $repository->findOneBy([
  63.                 'token' => $userToken,
  64.             ]);
  65.             if (null === $userRegistration) {
  66.                 throw new Exception('Invalid token');
  67.             }
  68.             if ($userRegistration->getLawFirm()) {
  69.                 throw new Exception('token expired');
  70.             }
  71.             $formToken $tokenManager
  72.                 ->getToken(LawFirmCreateFormType::TOKEN_STRING)
  73.                 ->getValue();
  74.             $countries Countries::getNames($request->getLocale());
  75.             $languages LanguageEnum::getWebLanguages();
  76.             $currencies Currencies::getNames();
  77.             array_walk($currencies, function (string &$currency) {
  78.                 $currency ucfirst($currency);
  79.             });
  80.             return $this->render('registration/register_step_two.html.twig', [
  81.                 'countries' => $countries,
  82.                 'languages' => $languages,
  83.                 'currencies' => $currencies,
  84.                 'userToken' => $userToken,
  85.                 'formToken' => $formToken,
  86.             ]);
  87.         } catch (\Throwable $e) {
  88.             $logger->error('Error on registration step 2', [
  89.                 'exception' => $e,
  90.             ]);
  91.             return $this->redirectToRoute('registration_user_create_form');
  92.         }
  93.     }
  94.     /**
  95.      * @Route("/one-last-thing", name="law_firm_survey", options={"expose"=true})
  96.      * @param CsrfTokenManagerInterface $tokenManager
  97.      * @return Response
  98.      */
  99.     public function lawFirmInformationSurvey(CsrfTokenManagerInterface $tokenManager) : Response
  100.     {
  101.         $formToken $tokenManager
  102.             ->getToken('law_firm_informations_form')
  103.             ->getValue();
  104.         return $this->render('registration/law_firm_survey.html.twig', [
  105.             'jobTitles' => UserJobTitleEnum::getChoicesWithLabels(),
  106.             'organizationTypes' => LawFirmOrganizationEnum::getChoicesWithLabels(),
  107.             'equipments' => LawFirmEquipmentEnum::getChoicesWithLabels(),
  108.             'formToken' => $formToken,
  109.         ]);
  110.     }
  111. }