src/Controller/RegistrationController.php line 40

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; // Supprimé car Doctrine n'est pas utilisé
  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 - DISABLED
  19. class RegistrationController extends AbstractController
  20. {
  21.     /**
  22.      * @Route("/register", name="app_register")
  23.      */
  24.     public function register(CallApiServices $callApiServicesQuestionMailService $questionMailServiceRequest $requestUserPasswordHasherInterface $userPasswordHasherUserAuthenticatorInterface $userAuthenticatorUserContactAuthenticator $authenticator): Response
  25.     {
  26.         $user = new Client();
  27.         $serviceId $this->getParameter('app.serviceId');
  28.         $accountId $this->getParameter('app.accountId');
  29.         $config $callApiServices->configuratationPlateforme($accountId$serviceId);
  30.         $session $request->getSession();
  31.         $addressIp $request->getClientIp();
  32.         if ($session->get('parrainId') == null) {
  33.             $parrainId "0";
  34.         } else {
  35.             $parrainId $session->get('parrainId');
  36.         }
  37.         $recaptchaKey $config['recaptchaTab']['sitekey'];
  38.         $secretkey $config['recaptchaTab']['secretkey'];
  39.         $messageError "";
  40.         $form $this->createForm(RegistrationFormType::class, $user);
  41.         $form->handleRequest($request);
  42.         if ($form->isSubmitted() && $form->isValid()) {
  43.             // ReCaptcha verification disabled
  44.             /*
  45.             $recaptcha = new ReCaptcha($secretkey);
  46.             $resp = $recaptcha->verify($request->request->get('g-recaptcha-response'), $request->getClientIp());
  47.             if (!$resp->isSuccess()) {
  48.                 // Do something if the submit wasn't valid ! Use the message to show something
  49.                 $messageError = "Le reCAPTCHA n'a pas été saisi correctement. Réessayez.";
  50.             } else {
  51.             */
  52.                 // encode the plain password
  53.                 $user->setPassword($form->get('plainPassword')->getData());
  54.                 $clientInscription $callApiServices->clientInscription(
  55.                     $serviceId,
  56.                     $parrainId,
  57.                     $user->getGenre(),
  58.                     $user->getEmail(),
  59.                     $user->getPassword(),
  60.                     $user->getLastName(),
  61.                     $user->getFirstName(),
  62.                     $user->getPhoneNumber(),
  63.                     $addressIp
  64.                 );
  65.                 // verifier si pas erreur
  66.                 if (isset($clientInscription['responseCode']) && ($clientInscription['responseCode'] == '403')) {
  67.                     $this->addFlash("inscription""Un enregistrement correspondant existe déjà ");
  68.                     return $this->render('registration/register.html.twig', [
  69.                         'registrationForm' => $form->createView(),
  70.                         "recaptchaKey" => $recaptchaKey,
  71.                         "messageError" => $messageError,
  72.                     ]);
  73.                 } else {
  74.                     $user->setCode($clientInscription['code']);
  75.                     $user->setServiceId($serviceId);
  76.                     $this->addFlash("inscription""Vous avez bien été inscrit! Vous allez recevoir un mail afin d'activer votre compte d'un moment à l'autre.
  77.                     Si vous ne recevez pas le mail, veuillez vérifier dans votre boîte SPAM ou courrier indésirable, s'il s'y trouve !! ");
  78.                 }
  79.                 // Envoie de Mail.
  80.                 $questionMailService->checkMail($user$request$accountId$serviceId$callApiServices);
  81.                 return $this->redirectToRoute("app_login");
  82.             // } // ReCaptcha verification disabled
  83.         }
  84.         return $this->render('registration/register.html.twig', [
  85.             'registrationForm' => $form->createView(),
  86.             "recaptchaKey" => $recaptchaKey,
  87.             "messageError" => $messageError,
  88.         ]);
  89.     }
  90.     /**
  91.      * @Route("/checkRegister", name="app_check")
  92.      */
  93.     public function checkRegister(CallApiServices $callApiServicesRequest $requestUserPasswordHasherInterface $userPasswordHasherUserAuthenticatorInterface $userAuthenticatorUserContactAuthenticator $authenticator): Response
  94.     {
  95.         $validation = [
  96.             'serviceId' => $request->get('serviceId'),
  97.             'username' => $request->get('username'),
  98.             'password' => $request->get('password'),
  99.             'code' => $request->get('code')
  100.         ];
  101.         $user $callApiServices->clientInscriptionValidation($validation['serviceId'], $validation['username'], $validation['password'], $validation['code'], 1);
  102.         if (isset($user['responseCode']) && ($user['responseCode'] == '403')) {
  103.             $this->addFlash("inscriptionCheck""Votre compte adéja été activer vous ne pouvez plus l'activé");
  104.         } else {
  105.             $this->addFlash("inscriptionCheck""Votre compte a bien été activé, vous pouver désormais profiter de toutes les fonctionnalités de la plateforme.");
  106.         }
  107.         return $this->redirectToRoute("app_login");
  108.     }
  109. }