src/Controller/RegistrationController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Client;
  4. use App\Entity\Config;
  5. use App\Entity\UserContact;
  6. use App\Form\RegistrationFormType;
  7. use App\Form\SocialRegistrationFormType;
  8. use App\Security\UserContactAuthenticator;
  9. use App\Services\CallApiServices;
  10. use App\Services\QuestionMailService;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
  18. use ReCaptcha\ReCaptcha// Include the recaptcha lib
  19. class RegistrationController extends AbstractController
  20. {
  21.     /**
  22.      * @Route("/register", name="app_register")
  23.      */
  24.     public function register(CallApiServices $callApiServicesQuestionMailService $questionMailServiceRequest $requestUserPasswordHasherInterface $userPasswordHasherUserAuthenticatorInterface $userAuthenticatorUserContactAuthenticator $authenticatorEntityManagerInterface $entityManager): Response
  25.     {
  26.         $user = new Client();
  27.         
  28.         $serviceId $this->getParameter('app.serviceId');
  29.         $accountId $this->getParameter('app.accountId');
  30.         $config $callApiServices->configuratationPlateforme($accountId$serviceId);
  31.         $session $request->getSession();
  32.         $addressIp =$request->getClientIp();
  33.         if ($session->get('parrainId') == null){
  34.             $parrainId "0"
  35.         }else{
  36.             $parrainId $session->get('parrainId');
  37.         }
  38.         $recaptchaKey $config['recaptchaTab']['sitekey'];
  39.         $secretkey $config['recaptchaTab']['secretkey'];
  40.         $messageError "";
  41.         $form $this->createForm(RegistrationFormType::class, $user);
  42.         $form->handleRequest($request);
  43.         if ($form->isSubmitted() && $form->isValid()) {
  44.             $recaptcha = new ReCaptcha($secretkey);
  45.            
  46.             $resp $recaptcha->verify($request->request->get('g-recaptcha-response'), $request->getClientIp());
  47.           
  48.             if (!$resp->isSuccess()) {
  49.               // Do something if the submit wasn't valid ! Use the message to show something
  50.               $messageError "Le reCAPTCHA n'a pas été saisi correctement. Réessayez.";
  51.     
  52.             } else {
  53.                     
  54.                 // encode the plain password
  55.                 $user->setPassword($form->get('plainPassword')->getData());
  56.                 $clientInscription $callApiServices->clientInscription(
  57.                     $serviceId,
  58.                     $parrainId,
  59.                     $user->getGenre(),
  60.                     $user->getEmail(),
  61.                     $user->getPassword(),
  62.                     $user->getLastName(),
  63.                     $user->getFirstName(),
  64.                     $user->getPhoneNumber(),
  65.                     $addressIp
  66.                 );
  67.                 $user->setCode($clientInscription['code']);
  68.                 $user->setServiceId($serviceId);
  69.         
  70.                 if (isset($clientInscription['code']) && ($clientInscription['code'] == '403')) {
  71.                     $this->addFlash("inscription""Un enregistrement correspondant existe déjà ");
  72.                     return $this->render('registration/register.html.twig', [
  73.                         'registrationForm' => $form->createView(),
  74.                         "recaptchaKey" => $recaptchaKey,
  75.                         "messageError" => $messageError,
  76.                     ]);
  77.                 } else {
  78.                         $this->addFlash("inscription""Bienvenue dans notre cabinet de voyance.
  79.                         Votre inscription a été prise en compte.
  80.                         Vous allez recevoir un mail pour activer votre compte.
  81.                         Pensez à vérifier dans les SPAM si vous n’avez pas reçu le mail.");
  82.                 }
  83.                 // Envoie de Mail.
  84.                 $questionMailService->checkMail($user$request);
  85.                 return $this->redirectToRoute("app_login");
  86.             }
  87.            
  88.         }
  89.         return $this->render('registration/register.html.twig', [
  90.             'registrationForm' => $form->createView(),
  91.             "recaptchaKey" => $recaptchaKey,
  92.             "messageError" => $messageError,
  93.         ]);
  94.     }
  95.   
  96.     /**
  97.      * @Route("/checkRegister", name="app_check")
  98.      */
  99.     public function checkRegister(CallApiServices $callApiServicesRequest $requestUserPasswordHasherInterface $userPasswordHasherUserAuthenticatorInterface $userAuthenticatorUserContactAuthenticator $authenticatorEntityManagerInterface $entityManager): Response
  100.     {
  101.         // @todo No password passed in URL!
  102.         $validation = [
  103.             'serviceId' => $request->get('serviceId'),
  104.             'username' => $request->get('username'),
  105.             'password' => $request->get('password'),
  106.             'code' => $request->get('code')
  107.         ];
  108.   
  109.         $user $callApiServices->clientInscriptionValidation($validation['serviceId'], $validation['username'], $validation['password'], $validation['code'], 1);
  110.         
  111.         
  112.         if (isset($user['code']) && ($user['code'] == '403')) {
  113.            
  114.         $this->addFlash("inscriptionCheck""Votre compte adéja été activer vous ne pouvez plus l'activé");  
  115.         }else{
  116.             $this->addFlash("inscriptionCheck""Votre compte a bien été activé, vous pouver désormais profiter de toutes les fonctionnalités de la plateforme.");
  117.          }
  118.         return $this->redirectToRoute("app_login");
  119.     }
  120. }