src/Controller/Marketplace/ExpertController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Marketplace;
  3. use App\Entity\Specialist;
  4. use App\Form\SpecialistLightType;
  5. use App\Repository\SpecialistRepository;
  6. use App\Security\SpecialistAuthenticator;
  7. use App\Service\EmailService;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  14. use Symfony\Component\Uid\Uuid;
  15. /**
  16.  * @Route("/", name="app_expert_")
  17.  */
  18. class ExpertController extends AbstractController
  19. {
  20.      /**
  21.      * @var emailService
  22.      */
  23.     private $emailService;
  24.      /**
  25.      * @var UrlGeneratorInterface
  26.      */
  27.     private $urlGenerator;
  28.     public function __construct(EmailService $emailServiceUrlGeneratorInterface $urlGenerator)
  29.     {
  30.         $this->emailService $emailService;
  31.         $this->urlGenerator $urlGenerator;
  32.     }
  33.     /**
  34.      * @Route("devenir-expert", name="signup")
  35.      */
  36.     public function index(Request $requestEntityManagerInterface $entityManagerSpecialistRepository $specialistRepo): Response
  37.     {
  38.         $success false;
  39.         if (!empty($request->query->get('signup'))) {
  40.             $success true;
  41.         }
  42.         $specialist = new Specialist();
  43.         $options = [
  44.             'pwd_required' => true,
  45.             'specialist_reg' => true,
  46.         ];
  47.         $form $this->createForm(SpecialistLightType::class, $specialist$options);
  48.         $form->handleRequest($request);
  49.         if ($form->isSubmitted() && $form->isValid()) {
  50.             $existingSpecialist $specialistRepo->findOneBy(
  51.                 [
  52.                     'tel' => $specialist->getTel(),
  53.                     ]
  54.                 );
  55.             if ($existingSpecialist == null) {
  56.                 $validUuid Uuid::v1();
  57.                 $specialist->setIsVirtualEvent(true);
  58.                 $specialist->getUser()->setActive(true);
  59.                 $specialist->setSpecialistTags([]);
  60.                 $specialist->setUuid($validUuid);
  61.                 $specialist->setStatus(Specialist::STATUS_WAITING_MAIL_CONFIRMATION);
  62.                 try {
  63.                     $entityManager->persist($specialist);
  64.                     $entityManager->flush();
  65.                     $entityManager->refresh($specialist);
  66.                     $this->emailService->sendSpecialistAccountConfirmation($specialist);
  67.                     $this->addFlash('success''Un mail de confirmation vient de vous être envoyé. Afin de finaliser votre inscription veuillez cliquer sur le lien présent dans ce mail. A très vite sur ULTEAM pour découvrir nos opportunités');
  68.                     return $this->redirectToRoute('marketplace_app_expert_signup', ['signup' => "success"]);
  69.                     // return $this->generateUrl(SpecialistAuthenticator::LOGIN_ROUTE);
  70.                     // return $this->redirect($this->getParameter('ULTEAM_LIVE_HOST').$this->generateUrl(SpecialistAuthenticator::LOGIN_ROUTE));
  71.                 }catch (\Exception $e){
  72.                     $this->addFlash('errorGlobal''Une erreur est survenue');
  73.                     // return $this->redirectToRoute(SpecialistAuthenticator::LOGIN_ROUTE);
  74.                 }
  75.             }elseif ($existingSpecialist != null && $existingSpecialist->getStatus() == Specialist::STATUS_REFUSED) {
  76.                 $this->addFlash('errorGlobal''Désolé mais la connexion à ton compte n\'est pas possible actuellement');
  77.                 // return $this->redirectToRoute(SpecialistAuthenticator::LOGIN_ROUTE);
  78.             }else {
  79.                 $this->addFlash('errorGlobal''Un expert avec ce numero de téléphone existe déjà');
  80.                 // return $this->redirectToRoute(SpecialistAuthenticator::LOGIN_ROUTE);
  81.             }
  82.         }
  83.         return $this->render('marketplace/expert/index.html.twig', [
  84.             'form' => $form->createView(),
  85.             'success' => $success
  86.         ]);
  87.     }
  88. }