src/Controller/SignUpController.php line 1575

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Cookie;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use App\Entity\SignUpProcess;
  13. use App\Entity\SignUpCode;
  14. use App\Entity\GmbPage;
  15. use App\Entity\MarketerClientRequest;
  16. use Orc\SaasBundle\Entity\Client;
  17. use Orc\SaasBundle\Entity\Site;
  18. use Orc\UserBundle\Entity\User;
  19. use Orc\BookingBundle\Entity\DateTime;
  20. use Orc\BookingBundle\Entity\Region;
  21. use Orc\BookingBundle\Entity\Boundary;
  22. use Orc\BookingBundle\Entity\Location;
  23. use Orc\BookingBundle\Entity\Service;
  24. use Orc\BookingBundle\Entity\Crew;
  25. use Orc\BookingBundle\Entity\Worker;
  26. use Orc\BookingBundle\Booking\TimezoneGuesser;
  27. use Orc\SaasBundle\Form\Type\ClientType;
  28. use Orc\SaasBundle\Form\Type\RegistrationFormType;
  29. use App\Repository\SignUpProcessRepository;
  30. use App\Repository\SignUpCodeRepository;
  31. use App\Service\BaseService;
  32. use App\Service\BookingUtilService;
  33. use App\Service\Mapservice;
  34. use App\Service\IntercomIntegrationService;
  35. use App\Security\LoginFormAuthenticator;
  36. use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
  37. use Symfony\Component\EventDispatcher\EventDispatcher;
  38. use Orc\SaasBundle\SaasEvents;
  39. use Orc\BillingBundle\EventListener\CreateCustomer;
  40. use Orc\SaasBundle\Event\ClientEvent;
  41. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  42. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  43. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  44. use Symfony\Component\Serializer\Serializer;
  45. use Twilio\Rest\Client as TwilioClient;
  46. use Ramsey\Uuid\Uuid;
  47. use Mobile_Detect;
  48. class SignUpController extends AbstractController
  49. {
  50.     private $doctrine null;
  51.     private $entityManager null;
  52.     private $signUpProcessRepository null;
  53.     private $signUpCodeRepository null;
  54.     private $loginFormAuthenticator null;
  55.     private $guardAuthenticatorHandler null;
  56.     private $timezoneGuesser null;
  57.     private $createCustomer null;
  58.     private $request null;
  59.     private $bookingUtilService null;
  60.     private $mapservice null;
  61.     private $intercomIntegrationService null;
  62.     public function __construct(ManagerRegistry $doctrineUserPasswordEncoderInterface $passwordEncoderLoginFormAuthenticator $loginFormAuthenticatorGuardAuthenticatorHandler $guardAuthenticatorHandlerCreateCustomer $createCustomerRequestStack $requestStackTimezoneGuesser $timezoneGuesserBookingUtilService $bookingUtilServiceMapservice $mapserviceIntercomIntegrationService $intercomIntegrationService) {
  63.         $this->doctrine $doctrine;
  64.         $this->entityManager $doctrine->getManager();
  65.         $this->signUpProcessRepository $doctrine->getRepository(SignUpProcess::class);
  66.         $this->signUpCodeRepository $doctrine->getRepository(SignUpCode::class);
  67.         $this->passwordEncoder $passwordEncoder;
  68.         $this->loginFormAuthenticator $loginFormAuthenticator;
  69.         $this->guardAuthenticationHandler $guardAuthenticatorHandler;
  70.         $this->createCustomer $createCustomer;
  71.         $this->timezoneGuesser $timezoneGuesser;
  72.         $this->request $requestStack->getCurrentRequest();
  73.         $this->encoders = [new XmlEncoder(), new JsonEncoder()];
  74.         $this->normalizers = [new ObjectNormalizer()];
  75.         $this->serializer = new Serializer($this->normalizers$this->encoders);
  76.         $this->bookingUtilService $bookingUtilService;
  77.         $this->mapservice $mapservice;
  78.         $this->intercomIntegrationService $intercomIntegrationService;
  79.     }
  80.     private $screens = [
  81.         'input-login',
  82.         'input-company',
  83.         'input-servicearea',
  84.         'input-service',
  85.         'input-gbp',
  86.         'commit',
  87.         'complete'
  88.     ];
  89.     private $screensmap = [
  90.         'input-login' => 'sign_up_login',
  91.         'input-company' => 'sign_up_company',
  92.         'input-servicearea' => 'sign_up_servicearea',
  93.         'input-service' => 'sign_up_service',
  94.         'input-gbp' => 'sign_up_gbp',
  95.         'commit' => 'sign_up_commit',
  96.         'complete' => 'sign_up_complete'
  97.     ];
  98.     private function checkSignUpProcess($request) {
  99.         $_sign_up_code_ $request->cookies->get('_sign_up_code_');
  100.         $signUpProcess null;
  101.         if ($_sign_up_code_ == null) {
  102.             $signUpProcess null;
  103.         } else {
  104.             $signUpProcess $this->signUpProcessRepository->findOneBy(['code' => $_sign_up_code_'status' => 'form']);
  105.         }
  106.         return $signUpProcess;
  107.     }
  108.     protected function getUrlFromName($name) {
  109.         $schedulingwebsite strtolower(preg_replace('/[^a-zA-Z0-9\-]+/i'''$name));
  110.         return $schedulingwebsite;
  111.     }
  112.     private function generateSignUpProcess($request) {
  113.         $now = new \DateTime();
  114.         $nowPlus48h = clone $now;
  115.         $nowPlus48h->add(new \DateInterval('PT48H'));
  116.         $uuid Uuid::uuid4();
  117.         $suuid $uuid->toString();
  118.         $_sign_up_code_ $suuid;
  119.         $via $request->query->get('via');
  120.         if ($via == null) {
  121.             $rewardful_referral $request->cookies->get('rewardful_referral');
  122.             if ($rewardful_referral != null) {
  123.                 $sjson urldecode($rewardful_referral);
  124.                 $ojson json_decode($sjson);
  125.                 if ($ojson != null && property_exists($ojson'affiliate') && $ojson->affiliate != null && property_exists($ojson->affiliate'token') && $ojson->affiliate->token != null) {
  126.                     $via $ojson->affiliate->token;
  127.                 }
  128.             }
  129.         }
  130.         $redirect_mode '';
  131.         $redirect_uri $request->query->get('redirect_uri');
  132.         
  133.         if ($redirect_uri == null) {
  134.             $redirect_uri '';
  135.         }
  136.         if ($redirect_uri != '') {
  137.             $redirect_mode 'fbe';
  138.         }
  139.         $suname $request->query->get('suname');
  140.         if ($suname === null) {
  141.             $suname '';
  142.         }
  143.         $suemail $request->query->get('suemail');
  144.         if ($suemail === null) {
  145.             $suemail '';
  146.         }
  147.         $suphone $request->query->get('suphone');
  148.         if ($suphone === null) {
  149.             $suphone '';
  150.         }
  151.         $susignupcode $request->query->get('signupcode');
  152.         if ($susignupcode === null) {
  153.             $susignupcode '';
  154.         }
  155.         $companyname $request->request->get('fullname');
  156.         if ($companyname == null && $suname != null) {
  157.             $companyname $suname;
  158.         }
  159.         $email $request->request->get('email');
  160.         if ($email == null && $suemail != null) {
  161.             $email $suemail;
  162.         }
  163.         $phone $request->request->get('phone');
  164.         if ($phone == null && $suphone != null) {
  165.             $phone $suphone;
  166.         }
  167.         $signupcode $request->request->get('signupcode');
  168.         if ($signupcode == null && $susignupcode != null) {
  169.             $signupcode $susignupcode;
  170.         }
  171.         $signUpProcess = new SignUpProcess();
  172.         $signUpProcess->setCode($_sign_up_code_);
  173.         $signUpProcess->setStatus('form');
  174.         $signUpProcess->setScreen('input-login');
  175.         $signUpProcess->setStep('input-login');
  176.         $signUpProcess->setCompanyName($companyname != null $companyname '');
  177.         if ($companyname != null) {
  178.             $schedulingWebSite $this->getUrlFromName($companyname);
  179.             $domain_suffix '.' substr($request->server->get('SERVER_NAME'), 6);
  180.             $schedulingWebSiteFull "$schedulingWebSite$domain_suffix";
  181.             $signUpProcess->setSchedulingWebsite($schedulingWebSite);
  182.             $signUpProcess->setSchedulingWebsiteFull($schedulingWebSiteFull);
  183.         } else {
  184.             $signUpProcess->setSchedulingWebsite('');
  185.             $signUpProcess->setSchedulingWebsiteFull('');
  186.         }
  187.         $signUpProcess->setEmail($email != null $email '');
  188.         $signUpProcess->setPhoneNumber($phone != null $phone '');
  189.         $signUpProcess->setPassword('');
  190.         $signUpProcess->setConfirmPassword('');
  191.         $signUpProcess->setLocationText('');
  192.         $signUpProcess->setFlatRegions('');
  193.         $signUpProcess->setNameOfService('');
  194.         $signUpProcess->setTimeRequired(0);
  195.         $signUpProcess->setCreatedAt($now);
  196.         $signUpProcess->setUpdatedAt($now);
  197.         $signUpProcess->setExpiresAt($nowPlus48h);
  198.         $signUpProcess->setIpAddress($request->getClientIp());
  199.         try {
  200.             $o $this->validateSignupcode($request$signUpProcessfalse);
  201.             if ($o === null || !$o["valid"]) {
  202.                 $signupcode '';
  203.             }
  204.         } catch (\Throwable $throwable) {
  205.             $signupcode '';
  206.         }
  207.         
  208.         $signUpProcess->setSignupcode($signupcode);
  209.         $signUpProcess->setVia($via);
  210.         $signUpProcess->setRedirectMode($redirect_mode);
  211.         $signUpProcess->setFbeRedirectUri($redirect_uri);
  212.         $this->entityManager->persist($signUpProcess);
  213.         $this->entityManager->flush();
  214.         return $signUpProcess;
  215.     }
  216.     private function setCookie($response$value) {
  217.         $now = new \DateTime();
  218.         $dt = clone $now;
  219.         $dt->add(new \DateInterval('PT24H'));
  220.         $response->headers->setCookie(new Cookie('_sign_up_code_'$value$dt'/sign/up'));
  221.     }
  222.     private function unsetCookie($response) {
  223.         $response->headers->clearCookie('_sign_up_code_''/sign/up'null);
  224.     }
  225.     private function doStepRedirectionGET($request$signUpProcess) {
  226.         switch ($signUpProcess->getScreen()) {
  227.             case 'input-login':
  228.                 {
  229.                     return $this->redirect($this->generateUrl('sign_up_login'));
  230.                 }
  231.                 break;
  232.             case 'input-company':
  233.                 {
  234.                     return $this->redirect($this->generateUrl('sign_up_company'));
  235.                 }
  236.                 break;
  237.             case 'input-servicearea':
  238.                 {
  239.                     return $this->redirect($this->generateUrl('sign_up_servicearea'));
  240.                 }
  241.                 break;
  242.             case 'input-service':
  243.                 {
  244.                     return $this->redirect($this->generateUrl('sign_up_service'));
  245.                 }
  246.                 break;
  247.             case 'input-gbp':
  248.                 {
  249.                     return $this->redirect($this->generateUrl('sign_up_gbp'));
  250.                 }
  251.                 break;
  252.             default:
  253.                 {
  254.                     //return $this->step_company($request);
  255.                     //return $this->forward('App\Controller\SignUpController::step_company', array());
  256.                     return new Response(
  257.                         'INVALID STEP',
  258.                         Response::HTTP_OK,
  259.                         ['content-type' => 'text/html']
  260.                     );
  261.                 }
  262.         }
  263.     }
  264.     private function setGoToScreenOnSignUpProcess($signUpProcess$newscreen) {
  265.         $now = new \DateTime();
  266.         $newposition array_search($newscreen$this->screens);
  267.         if ($newposition === false) {
  268.             return;
  269.         }
  270.         $currentstep array_search($signUpProcess->getStep(), $this->screens);
  271.         if ($newposition $currentstep) {
  272.             $signUpProcess->setStep($newscreen);
  273.         }
  274.         $signUpProcess->setScreen($newscreen);
  275.         $signUpProcess->setUpdatedAt($now);
  276.         $signUpProcess->setIpAddress($this->request->getClientIp());
  277.         $this->entityManager->persist($signUpProcess);
  278.         $this->entityManager->flush();
  279.     }
  280.     private function redirectOnInvalidStep($signUpProcess$screen) {
  281.         $position array_search($screen$this->screens);
  282.         if ($position === false) {
  283.             return $this->redirect($this->generateUrl($this->screensmap[$signUpProcess->getStep()]));
  284.         }
  285.         $currentstep array_search($signUpProcess->getStep(), $this->screens);
  286.         if ($position $currentstep) {
  287.             return $this->redirect($this->generateUrl($this->screensmap[$signUpProcess->getStep()]));
  288.         }
  289.         return null;
  290.     }
  291.     private function doStepCompany($request$signUpProcess) {
  292.         $now = new \DateTime();
  293.         $domain_suffix '.' substr($request->server->get('SERVER_NAME'), 6);
  294.         if ($signUpProcess->getPhoneNumber() != $request->request->get('phone_number')) {
  295.             $signUpProcess->setConfirmationCodeVerified(false);
  296.         }
  297.         $signUpProcess->setCompanyName($request->request->get('company_name'));
  298.         $signUpProcess->setPhoneNumber($request->request->get('phone_number'));
  299.         $signUpProcess->setSchedulingWebsite($request->request->get('scheduling_website'));
  300.         $signUpProcess->setSchedulingWebsiteFull($request->request->get('scheduling_website') . $domain_suffix);
  301.         $signUpProcess->setUpdatedAt($now);
  302.         $signUpProcess->setIpAddress($this->request->getClientIp());
  303.         $this->entityManager->persist($signUpProcess);
  304.         $this->entityManager->flush();
  305.         return true;
  306.     }
  307.     private function doStepLogin($request$signUpProcess) {
  308.         $now = new \DateTime();
  309.         $signupcode $request->request->get('signupcode');
  310.         $rexception null;
  311.         $signUpCode null;
  312.         try {
  313.             $o $this->validateSignupcode($request$signUpProcessfalse);
  314.             if ($o !== null && $o["valid"]) {
  315.                 $signUpCode $o["signUpCode"];
  316.             }
  317.         } catch (\Exception $e) {
  318.             $rexception $e;
  319.         }
  320.         $signUpProcess->setEmail($request->request->get('email'));
  321.         $signUpProcess->setPassword($request->request->get('password'));
  322.         $signUpProcess->setConfirmPassword($request->request->get('confirm_password'));
  323.         $signUpProcess->setServiceType($request->request->get('service_type'));
  324.         $signUpProcess->setSignupcode($signupcode);
  325.         $signUpProcess->setUpdatedAt($now);
  326.         $signUpProcess->setIpAddress($this->request->getClientIp());
  327.         $this->entityManager->persist($signUpProcess);
  328.         $this->entityManager->flush();
  329.         if ($rexception != null) {
  330.             throw $rexception;
  331.         }
  332.         return true;
  333.     }
  334.     private function doStepServiceArea($request$signUpProcess) {
  335.         $now = new \DateTime();
  336.         $signUpProcess->setLocationText($request->request->get('location_text'));
  337.         $signUpProcess->setFlatRegions($request->request->get('flat_regions'));
  338.         $signUpProcess->setUpdatedAt($now);
  339.         $signUpProcess->setIpAddress($this->request->getClientIp());
  340.         $this->entityManager->persist($signUpProcess);
  341.         $this->entityManager->flush();
  342.         return true;
  343.     }
  344.     private function doStepService($request$signUpProcess) {
  345.         $now = new \DateTime();
  346.         $stimerequired $request->request->get('time_required');
  347.         if ($stimerequired == null || $stimerequired == '') {
  348.             $stimerequired '00:00';
  349.         }
  350.         $stimerequired preg_replace("/[^0-9]/"""$stimerequired );
  351.         $stimerequired_length strlen($stimerequired);
  352.         if ($stimerequired_length 4) {
  353.             $stimerequired sprintf('%04s'$stimerequired);
  354.         }
  355.         $stimerequired_hours substr($stimerequired0$stimerequired_length 2);
  356.         $stimerequired_minutes substr($stimerequired$stimerequired_length 22);
  357.         $itimerequired_hours intval($stimerequired_hours);
  358.         $itimerequired_minutes intval($stimerequired_minutes);
  359.         $itimerequired $itimerequired_hours 60 $itimerequired_minutes;
  360.         $signUpProcess->setNameOfService($request->request->get('name_of_service'));
  361.         $signUpProcess->setTimeRequired($itimerequired);
  362.         $signUpProcess->setUpdatedAt($now);
  363.         $signUpProcess->setIpAddress($this->request->getClientIp());
  364.         $this->entityManager->persist($signUpProcess);
  365.         $this->entityManager->flush();
  366.         return true;
  367.     }
  368.     private function doStepGbp($request$signUpProcess) {
  369.         $now = new \DateTime();
  370.         $gmb_skip $request->request->get('gmb_skip');
  371.         $gmb_name $request->request->get('gmb_name');
  372.         $gmb_address $request->request->get('gmb_address');
  373.         $gmb_phone $request->request->get('gmb_phone');
  374.         if ($gmb_skip === 'true') {
  375.             $signUpProcess->setGmbSkip(true);
  376.             $signUpProcess->setGmbName(null);
  377.             $signUpProcess->setGmbAddress(null);
  378.             $signUpProcess->setGmbPhone(null);
  379.         } else {
  380.             $signUpProcess->setGmbSkip(false);
  381.             $signUpProcess->setGmbName($gmb_name);
  382.             $signUpProcess->setGmbAddress($gmb_address);
  383.             $signUpProcess->setGmbPhone($gmb_phone);
  384.         }
  385.         $signUpProcess->setUpdatedAt($now);
  386.         $signUpProcess->setIpAddress($this->request->getClientIp());
  387.         $this->entityManager->persist($signUpProcess);
  388.         $this->entityManager->flush();
  389.         return true;
  390.     }
  391.     private function doStepCommit($request$signUpProcess) {
  392.         $now = new \DateTime();
  393.         $timezone $this->timezoneGuesser->queryIpstack();
  394.         if ($timezone != null) {
  395.             $timezone $timezone['id'];
  396.         }
  397.         //dd($signUpProcess);
  398.         //dd($signUpProcess->getPhoneNumber());
  399.         $o $this->validateSignupcode($request$signUpProcesstrue);
  400.         if ($o === null || !$o["valid"] ) {
  401.             throw new \Exception("Unexpected error!");
  402.         }
  403.         $signUpCode $o["signUpCode"];
  404.         $marketerClientRequest null;
  405.         $client = new Client();
  406.         $client->setDateCreated($now);
  407.         $client->setParentDomain(substr($request->server->get('SERVER_NAME'), 6)); //$client->setParentDomain($this->getParameter('orc_saas.parentdomain'));
  408.         $client->setBrandingColor($this->getParameter('orc_saas.branding.defaultColor'));
  409.         $client->setName($signUpProcess->getCompanyName());
  410.         $client->setPhone($signUpProcess->getPhoneNumber());
  411.         $client->setEmail($signUpProcess->getEmail());
  412.         $client->setServiceType($signUpProcess->getServiceType());
  413.         $client->setArrivalWindow($signUpProcess->getServiceType() === 'fixed' 0); // It was 2 for clients whose service_type != 'fixed'
  414.         $client->setVia($signUpProcess->getVia());
  415.         $client->setSignupcode($signUpProcess->getSignupcode());
  416.         $client->setLive(true);
  417.         $client->setLiveNotified(true);
  418.         if ($signUpCode !== null && $signUpCode->getMarketer() !== null) {
  419.             $marketer $signUpCode->getMarketer();
  420.             $client->setMarketedBy($marketer);
  421.             $client->setOriginallyMarketedBy($marketer);
  422.             $client->setSignupsource('coupon');
  423.             $marketerClientRequest = new MarketerClientRequest();
  424.             $marketerClientRequest->setClient($client);
  425.             $marketerClientRequest->setMarketer($marketer);
  426.             $marketerClientRequest->setTimeSent($now);
  427.             $marketerClientRequest->setTimeAccepted($now);
  428.             $marketerClientRequest->setAccepted(MarketerClientRequest::STATUS_ACCEPTED);
  429.             $this->entityManager->persist($marketerClientRequest);
  430.         } else {
  431.             $client->setSignupsource('direct');
  432.         }
  433.         $client->setStatus(Client::STATUS_NEW);
  434.         if ($timezone != null) {
  435.             $client->setTimezone($timezone);
  436.         }
  437.         $site = new Site();
  438.         $site->setClient($client);
  439.         $client->setSite($site);
  440.         $site->setDomain($signUpProcess->getSchedulingWebsiteFull());
  441.         $this->entityManager->persist($site);
  442.         $this->entityManager->persist($client);
  443.         $this->entityManager->flush();
  444.         $clientId $client->getId();
  445.         $user = new User();
  446.         $user->setClient($client);
  447.         $user->setEmail($signUpProcess->getEmail());
  448.         $user->setPassword($signUpProcess->getPassword());
  449.         $user->setPassword($this->passwordEncoder->encodePassword($user$user->getPassword()));
  450.         $roles $user->getRoles();
  451.         $roles[] = 'ROLE_CLIENT';
  452.         $roles[] = 'ROLE_STAFF';
  453.         $user->setRoles($roles);
  454.         $client->setUser($user);
  455.         $o_flat_regions $signUpProcess->getFlatRegionsObject();
  456.         $regions = [];
  457.         $opregion null;
  458.         $oplocation null;
  459.         foreach ($o_flat_regions->regions as $o_region) {
  460.             
  461.             $addressDetails $this->mapservice->getAddressDetailsFromPlace($o_region->place);
  462.             $region = new Region();
  463.             $region->setClient($client);
  464.             $region->setName($o_region->name);
  465.             $region->setServiceType($signUpProcess->getServiceType());
  466.             //$region->setStatus(0);
  467.             $region->setAddress(array_key_exists('formatted_address'$addressDetails) && !empty($addressDetails['formatted_address']) ? $addressDetails['formatted_address'] : '');
  468.             $region->setStreet(array_key_exists('street'$addressDetails) && !empty($addressDetails['street']) ? $addressDetails['street'] : '');
  469.             $region->setCity(array_key_exists('city'$addressDetails) && !empty($addressDetails['city']) ? $addressDetails['city'] : '');
  470.             $region->setCode(array_key_exists('code'$addressDetails) && !empty($addressDetails['code']) ? $addressDetails['code'] : '');
  471.             $region->setProvince(array_key_exists('province'$addressDetails) && !empty($addressDetails['province']) ? $addressDetails['province'] : '');
  472.             $region->setCountry(array_key_exists('country'$addressDetails) && !empty($addressDetails['country']) ? $addressDetails['country'] : '');
  473.             $region->setLatitude(array_key_exists('latitude'$addressDetails) && !empty($addressDetails['latitude']) ? $addressDetails['latitude'] : 0.0);
  474.             $region->setLongitude(array_key_exists('longitude'$addressDetails) && !empty($addressDetails['longitude']) ? $addressDetails['longitude'] : 0.0);
  475.             foreach ($o_region->boundaries as $o_boundary) {
  476.                 $boundary = new Boundary();
  477.                 $boundary->setRegion($region);
  478.                 $boundary->setOrder(intval($o_boundary->order));
  479.                 //dd($addressDetails);
  480.                 $location = new Location();
  481.                 $location->setStreet(array_key_exists('street'$addressDetails) && !empty($addressDetails['street']) ? $addressDetails['street'] : '');
  482.                 $location->setCity(array_key_exists('city'$addressDetails) && !empty($addressDetails['city']) ? $addressDetails['city'] : '');
  483.                 $location->setCode(array_key_exists('code'$addressDetails) && !empty($addressDetails['code']) ? $addressDetails['code'] : '');
  484.                 $location->setProvince(array_key_exists('province'$addressDetails) && !empty($addressDetails['province']) ? $addressDetails['province'] : '');
  485.                 $location->setCountry(array_key_exists('country'$addressDetails) && !empty($addressDetails['country']) ? $addressDetails['country'] : '');
  486.                 $location->setLatitude($o_boundary->location->latitude);
  487.                 $location->setLongitude($o_boundary->location->longitude);
  488.                 $boundary->setLocation($location);
  489.                 $this->entityManager->persist($location);
  490.                 $this->entityManager->persist($boundary);
  491.                 $opregion $region;
  492.                 $oplocation $location;
  493.             }
  494.             $this->entityManager->persist($region);
  495.             $regions[] = $region;
  496.         }
  497.         $service = new Service();
  498.         $service->setClient($client);
  499.         $service->setName($signUpProcess->getNameOfService());
  500.         $service->setBaseTime($signUpProcess->getTimeRequired());
  501.         $service->setCutofftime(24);
  502.         $crew = new Crew();
  503.         $crew->setClient($client);
  504.         $crew->setName('Default Team');
  505.         foreach ($regions as $region) {
  506.             $crew->addRegion($region);
  507.         }
  508.         $crew->addService($service);
  509.         $worker = new Worker();
  510.         $worker->setClient($client);
  511.         $worker->setCrew($crew);
  512.         $worker->setUser($user);
  513.         $worker->setName('Admin');
  514.         $worker->setType(Worker::TYPE_ADMIN);
  515.         $crew->addWorker($worker);
  516.         $this->entityManager->persist($client);
  517.         $this->entityManager->persist($site);
  518.         $this->entityManager->persist($user);
  519.         $this->entityManager->persist($service);
  520.         $this->entityManager->persist($crew);
  521.         $this->entityManager->persist($worker);
  522.         $this->entityManager->flush();
  523.         if (!$client->getStripeId()) {
  524.             try {
  525.                 $dispatcher = new EventDispatcher();
  526.                 $dispatcher->addListener(SaasEvents::CLIENT_CREATE, [$this->createCustomer'onCreateClient']);
  527.                 $dispatcher->dispatch(new ClientEvent($client), SaasEvents::CLIENT_CREATE);
  528.             } catch (\Throwable $throwable) {
  529.                 // NOTHING
  530.                 dump('PASSED HERE');
  531.                 dump([
  532.                     'message' => $throwable->getMessage(),
  533.                     'file' => $throwable->getFile(),
  534.                     'line' => $throwable->getTrace(),
  535.                     'trace' => $throwable->getTrace()
  536.                 ]);
  537.                 dd('END');
  538.             }
  539.         }
  540.         $this->get('session')->set('original_url'sprintf("%s://%s/dashboard/googlecalendar/addstaffcalendars"$request->getScheme(), $signUpProcess->getSchedulingWebsiteFull()));
  541.         $client $this->entityManager->find('Orc\SaasBundle\Entity\Client'$clientId);
  542.         //$client->setStatus(Client::STATUS_ACTIVE);
  543.         $client->setArrivalWindow($signUpProcess->getServiceType() === 'fixed' 0);
  544.         //$this->entityManager->persist($client->getCustomer());
  545.         $this->entityManager->persist($client);
  546.         $this->entityManager->flush();
  547.         //dd($client);
  548.         $result_dummybooking $this->bookingUtilService->createDummyBooking($client$opregion$oplocation);
  549.         $dummybooking null;
  550.         if (count($result_dummybooking) == 0) {
  551.             //dd('GENERAL FAILURE DUMMY BOOKING');
  552.         } else if ($result_dummybooking[0] !== 'ok') {
  553.             //dd($result_dummybooking[0]);
  554.         } else {
  555.             $dummybooking $result_dummybooking[1];
  556.         }
  557.         $this->intercomIntegrationService->sendToIntercom($client->getId(), truetrue, [], []);
  558.         //$this->get('session')->set('client', $client->getId());
  559.         $gmb_skip $signUpProcess->getGmbSkip() ? 'true' 'false';
  560.         $gmb_name $signUpProcess->getGmbName();
  561.         $gmb_address $signUpProcess->getGmbAddress();
  562.         $gmb_phone $signUpProcess->getGmbPhone();
  563.         if ($gmb_skip !== 'true' && !empty($gmb_name) && !empty($gmb_address) && !empty($gmb_phone)) {
  564.             $oaddress = (array) $this->mapservice->getAddressDetailsExt($gmb_address);
  565.             $geocoordinates['unstructured_address'] = array_key_exists('raw'$oaddress) && $oaddress['raw'] !== null $oaddress['raw'] : '';
  566.             $oaddress = [
  567.                 'street_address' => array_key_exists('street_single'$oaddress) && $oaddress['street_single'] !== null $oaddress['street_single'] : '',
  568.                 'locality' => array_key_exists('city'$oaddress) && $oaddress['city'] !== null $oaddress['city'] : '',
  569.                 'region' => array_key_exists('province'$oaddress) && $oaddress['province'] !== null $oaddress['province'] : '',
  570.                 'postal_code' => array_key_exists('code'$oaddress) && $oaddress['code'] !== null $oaddress['code'] : '',
  571.                 'country' => array_key_exists('country'$oaddress) && $oaddress['country'] !== null $oaddress['country'] : ''
  572.             ];
  573.             $gmbPage = new GmbPage();
  574.             $gmbPage->setClient($client);
  575.             $gmbPage->setGmbEnabled(true);
  576.             $gmbPage->setGmbName($gmb_name);
  577.             $gmbPage->setGmbAddress($gmb_address);
  578.             $gmbPage->setGmbPhone($gmb_phone);
  579.             $gmbPage->setActionUrl($site->getDomain());
  580.             $client->setGmbEnabled(true);
  581.             $this->entityManager->persist($client);
  582.             $this->entityManager->persist($gmbPage);
  583.             $this->entityManager->flush();
  584.         }
  585.         return [
  586.             'client' => $client,
  587.             'user' => $user,
  588.             'crew' => $crew,
  589.             'service' => $service,
  590.             'dummybooking' => $dummybooking
  591.         ];
  592.     }
  593.     private function doStepComplete($request$signUpProcess) {
  594.         $now = new \DateTime();
  595.         $signUpProcess->setStatus('complete');
  596.         $signUpProcess->setUpdatedAt($now);
  597.         $signUpProcess->setIpAddress($this->request->getClientIp());
  598.         $this->entityManager->persist($signUpProcess);
  599.         $this->entityManager->flush();
  600.         return true;
  601.     }
  602.     private function doStepRedirectionPOST($request$signUpProcess) {
  603.         $now = new \DateTime();
  604.         $go $request->request->get('go');
  605.         switch ($signUpProcess->getScreen()) {
  606.             case 'input-login':
  607.                 {
  608.                     $b false;
  609.                     try {
  610.                         $b $this->doStepLogin($request$signUpProcess);
  611.                         if (!$b) {
  612.                             throw new \Exception("Unexpected error!");
  613.                         }
  614.                         $warningbody json_encode([
  615.                             'code' => 0,
  616.                             'message' => '',
  617.                             'trace' => null
  618.                         ]);
  619.                         $signUpProcess->setWarningstatus(1);
  620.                         $signUpProcess->setWarningbody($warningbody);
  621.                         $signUpProcess->setUpdatedAt($now);
  622.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  623.                         $this->entityManager->persist($signUpProcess);
  624.                         $this->entityManager->flush();
  625.                     } catch (\Throwable $throwable) {
  626.                         $warningbody json_encode([
  627.                             'code' => $throwable->getCode(),
  628.                             'line' => $throwable->getLine(),
  629.                             'file' => $throwable->getFile(),
  630.                             'message' => $throwable->getMessage(),
  631.                             'trace' => $throwable->getTrace()
  632.                         ]);
  633.                         $signUpProcess->setWarningstatus(1);
  634.                         $signUpProcess->setWarningbody($warningbody);
  635.                         $signUpProcess->setUpdatedAt($now);
  636.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  637.                         $this->entityManager->persist($signUpProcess);
  638.                         $this->entityManager->flush();
  639.                     }
  640.                     //dd($signUpProcess->getScreen());
  641.                     //dd($go);
  642.                     if ($b) {
  643.                         switch ($go) {
  644.                             case 'previous':
  645.                             case 'back';
  646.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-login');
  647.                                 return $this->redirect($this->generateUrl('sign_up_login'));
  648.                                 break;
  649.                             case 'next':
  650.                             default:
  651.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-company');
  652.                                 return $this->redirect($this->generateUrl('sign_up_company'));
  653.                                 break;
  654.                         }
  655.                     }
  656.                     return $this->redirect($this->generateUrl('sign_up_login'));
  657.                 }
  658.                 break;
  659.             case 'input-company':
  660.                 {
  661.                     $b false;
  662.                     try {
  663.                         $b $this->doStepCompany($request$signUpProcess);
  664.                         if (!$b) {
  665.                             throw new \Exception("Unexpected error!");
  666.                         }
  667.                         $warningbody json_encode([
  668.                             'code' => 0,
  669.                             'message' => '',
  670.                             'trace' => null
  671.                         ]);
  672.                         $signUpProcess->setWarningstatus(1);
  673.                         $signUpProcess->setWarningbody($warningbody);
  674.                         $signUpProcess->setUpdatedAt($now);
  675.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  676.                         $this->entityManager->persist($signUpProcess);
  677.                         $this->entityManager->flush();
  678.                     } catch (\Throwable $throwable) {
  679.                         $warningbody json_encode([
  680.                             'code' => $throwable->getCode(),
  681.                             'line' => $throwable->getLine(),
  682.                             'file' => $throwable->getFile(),
  683.                             'message' => $throwable->getMessage(),
  684.                             'trace' => $throwable->getTrace()
  685.                         ]);
  686.                         $signUpProcess->setWarningstatus(1);
  687.                         $signUpProcess->setWarningbody($warningbody);
  688.                         $signUpProcess->setUpdatedAt($now);
  689.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  690.                         $this->entityManager->persist($signUpProcess);
  691.                         $this->entityManager->flush();
  692.                     }
  693.                     if ($b) {
  694.                         switch ($go) {
  695.                             case 'previous':
  696.                             case 'back';
  697.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-login');
  698.                                 return $this->redirect($this->generateUrl('sign_up_login'));
  699.                                 break;
  700.                             case 'next':
  701.                             default:
  702.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-servicearea');
  703.                                 return $this->redirect($this->generateUrl('sign_up_servicearea'));
  704.                                 break;
  705.                         }
  706.                     }
  707.                     return $this->redirect($this->generateUrl('sign_up_company'));
  708.                 }
  709.                 break;
  710.             case 'input-servicearea':
  711.                 {
  712.                     $b false;
  713.                     try {
  714.                         $b $this->doStepServiceArea($request$signUpProcess);
  715.                         if (!$b) {
  716.                             throw new \Exception("Unexpected error!");
  717.                         }
  718.                         $warningbody json_encode([
  719.                             'code' => 0,
  720.                             'message' => '',
  721.                             'trace' => null
  722.                         ]);
  723.                         $signUpProcess->setWarningstatus(1);
  724.                         $signUpProcess->setWarningbody($warningbody);
  725.                         $signUpProcess->setUpdatedAt($now);
  726.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  727.                         $this->entityManager->persist($signUpProcess);
  728.                         $this->entityManager->flush();
  729.                     } catch (\Throwable $throwable) {
  730.                         $warningbody json_encode([
  731.                             'code' => $throwable->getCode(),
  732.                             'line' => $throwable->getLine(),
  733.                             'file' => $throwable->getFile(),
  734.                             'message' => $throwable->getMessage(),
  735.                             'trace' => $throwable->getTrace()
  736.                         ]);
  737.                         $signUpProcess->setWarningstatus(1);
  738.                         $signUpProcess->setWarningbody($warningbody);
  739.                         $signUpProcess->setUpdatedAt($now);
  740.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  741.                         $this->entityManager->persist($signUpProcess);
  742.                         $this->entityManager->flush();
  743.                     }
  744.                     if ($b) {
  745.                         switch ($go) {
  746.                             case 'previous':
  747.                             case 'back';
  748.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-company');
  749.                                 return $this->redirect($this->generateUrl('sign_up_company'));
  750.                                 break;
  751.                             case 'next':
  752.                             default:
  753.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-service');
  754.                                 return $this->redirect($this->generateUrl('sign_up_service'));
  755.                                 break;
  756.                         }
  757.                     }
  758.                     return $this->redirect($this->generateUrl('sign_up_servicearea'));
  759.                 }
  760.                 break;
  761.             case 'input-service':
  762.                 {
  763.                     $b false;
  764.                     try {
  765.                         $b $this->doStepService($request$signUpProcess);
  766.                         if (!$b) {
  767.                             throw new \Exception("Unexpected error!");
  768.                         }
  769.                         $warningbody json_encode([
  770.                             'code' => 0,
  771.                             'message' => '',
  772.                             'trace' => null
  773.                         ]);
  774.                         $signUpProcess->setWarningstatus(1);
  775.                         $signUpProcess->setWarningbody($warningbody);
  776.                         $signUpProcess->setUpdatedAt($now);
  777.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  778.                         $this->entityManager->persist($signUpProcess);
  779.                         $this->entityManager->flush();
  780.                     } catch (\Throwable $throwable) {
  781.                         $warningbody json_encode([
  782.                             'code' => $throwable->getCode(),
  783.                             'line' => $throwable->getLine(),
  784.                             'file' => $throwable->getFile(),
  785.                             'message' => $throwable->getMessage(),
  786.                             'trace' => $throwable->getTrace()
  787.                         ]);
  788.                         $signUpProcess->setWarningstatus(1);
  789.                         $signUpProcess->setWarningbody($warningbody);
  790.                         $signUpProcess->setUpdatedAt($now);
  791.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  792.                         $this->entityManager->persist($signUpProcess);
  793.                         $this->entityManager->flush();
  794.                     }
  795.                     if ($b) {
  796.                         switch ($go) {
  797.                             case 'previous':
  798.                             case 'back';
  799.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-servicearea');
  800.                                 return $this->redirect($this->generateUrl('sign_up_servicearea'));
  801.                                 break;
  802.                             case 'next':
  803.                             default:
  804.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-gbp');
  805.                                 return $this->redirect($this->generateUrl('sign_up_gbp'));
  806.                                 break;
  807.                         }
  808.                     }
  809.                     return $this->redirect($this->generateUrl('sign_up_service'));
  810.                 }
  811.                 break;
  812.             case 'input-gbp':
  813.                 {
  814.                     $b false;
  815.                     try {
  816.                         $b $this->doStepGbp($request$signUpProcess);
  817.                         if (!$b) {
  818.                             throw new \Exception("Unexpected error!");
  819.                         }
  820.                         $warningbody json_encode([
  821.                             'code' => 0,
  822.                             'message' => '',
  823.                             'trace' => null
  824.                         ]);
  825.                         $signUpProcess->setWarningstatus(1);
  826.                         $signUpProcess->setWarningbody($warningbody);
  827.                         $signUpProcess->setUpdatedAt($now);
  828.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  829.                         $this->entityManager->persist($signUpProcess);
  830.                         $this->entityManager->flush();
  831.                     } catch (\Throwable $throwable) {
  832.                         $warningbody json_encode([
  833.                             'code' => $throwable->getCode(),
  834.                             'line' => $throwable->getLine(),
  835.                             'file' => $throwable->getFile(),
  836.                             'message' => $throwable->getMessage(),
  837.                             'trace' => $throwable->getTrace()
  838.                         ]);
  839.                         $signUpProcess->setWarningstatus(1);
  840.                         $signUpProcess->setWarningbody($warningbody);
  841.                         $signUpProcess->setUpdatedAt($now);
  842.                         $signUpProcess->setIpAddress($this->request->getClientIp());
  843.                         $this->entityManager->persist($signUpProcess);
  844.                         $this->entityManager->flush();
  845.                     }
  846.                     if ($b) {
  847.                         switch ($go) {
  848.                             case 'previous':
  849.                             case 'back';
  850.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'input-service');
  851.                                 return $this->redirect($this->generateUrl('sign_up_service'));
  852.                                 break;
  853.                             case 'next':
  854.                             default:
  855.                                 $this->setGoToScreenOnSignUpProcess($signUpProcess'commit');
  856.                                 return $this->redirect($this->generateUrl('sign_up_commit'));
  857.                                 break;
  858.                         }
  859.                     }
  860.                     return $this->redirect($this->generateUrl('sign_up_gbp'));
  861.                 }
  862.                 break;
  863.             default:
  864.                 {
  865.                     //return $this->step_company($request);
  866.                     //return $this->forward('App\Controller\SignUpController::step_company', array());
  867.                     return new Response(
  868.                         'INVALID STEP',
  869.                         Response::HTTP_OK,
  870.                         ['content-type' => 'text/html']
  871.                     );
  872.                 }
  873.         }
  874.     }
  875.     /**
  876.      * @Route("/sign/up/step", name="sign_up_step")
  877.      */
  878.     public function step(Request $request): Response
  879.     {
  880.         $signUpProcess $this->checkSignUpProcess($request);
  881.         if ($signUpProcess == null) {
  882.             $response $this->redirect($this->generateUrl('sign_up_login'));
  883.             $this->unsetCookie($response);
  884.             return $response;
  885.         }
  886.         $screen $request->request->get('screen');
  887.         if ($screen != null) {
  888.             $this->setGoToScreenOnSignUpProcess($signUpProcess$screen);
  889.         }
  890.         if ($request->getMethod() == 'POST') {
  891.             return $this->doStepRedirectionPOST($request$signUpProcess);
  892.         } else {
  893.             return $this->doStepRedirectionGET($request$signUpProcess);
  894.         }
  895.     }
  896.     /**
  897.      * @Route("/sign/up", name="sign_up_login")
  898.      */
  899.     public function step_login(Request $request): Response
  900.     {
  901.         $now = new \DateTime();
  902.         $setCookie false;
  903.         $signUpProcess $this->checkSignUpProcess($request);
  904.         if ($signUpProcess == null) {
  905.             $signUpProcess $this->generateSignUpProcess($request);
  906.             $setCookie true;
  907.         } else {
  908.             $o $this->redirectOnInvalidStep($signUpProcess'input-login');
  909.             if ($o != null) {
  910.                 return $o;
  911.             } else {
  912.                 $signUpProcess->setScreen('input-login');
  913.                 $signUpProcess->setUpdatedAt($now);
  914.                 $signUpProcess->setIpAddress($this->request->getClientIp());
  915.                 $this->entityManager->persist($signUpProcess);
  916.                 $this->entityManager->flush();
  917.             }
  918.         }
  919.         $response $this->render('sign_up_process/step_login.html.twig', array(
  920.             'controller' => $this,
  921.             'code' => $signUpProcess->getCode(),
  922.             'screen' => 'input-login',
  923.             'headersteps' => true,
  924.             'complete' => false,
  925.             'controller_name' => 'SignUpController',
  926.             'next' =>  $this->generateUrl($this->screensmap['input-company']),
  927.             'signUpProcess' => $signUpProcess,
  928.             'displaywarning' => true,
  929.             'warningstatus' => $signUpProcess != null && $signUpProcess->getWarningstatus() != null $signUpProcess->getWarningstatus() : 0,
  930.             'warningbody' => $signUpProcess != null && $signUpProcess->getWarningbody() != null && $signUpProcess->getWarningbody() != '' json_decode($signUpProcess->getWarningbody()) : null,
  931.             'nextlabel' => 'CREATE ACCOUNT'
  932.         ));
  933.         if ($setCookie) {
  934.            $this->setCookie($response$signUpProcess->getCode());
  935.         }
  936.         return $response;
  937.     }
  938.     /**
  939.      * @Route("/sign/up/company", name="sign_up_company")
  940.      */
  941.     public function step_company(Request $request): Response
  942.     {
  943.         $now = new \DateTime();
  944.         $dt = clone $now;
  945.         $dt->add(new \DateInterval('PT24H'));
  946.         $setCookie false;
  947.         $signUpProcess $this->checkSignUpProcess($request);
  948.         if ($signUpProcess == null) {
  949.             return $this->redirect($this->generateUrl('sign_up_login'));
  950.         } else {
  951.             $o $this->redirectOnInvalidStep($signUpProcess'input-company');
  952.             if ($o != null) {
  953.                 return $o;
  954.             } else {
  955.                 $signUpProcess->setScreen('input-company');
  956.                 $signUpProcess->setUpdatedAt($now);
  957.                 $signUpProcess->setIpAddress($this->request->getClientIp());
  958.                 $this->entityManager->persist($signUpProcess);
  959.                 $this->entityManager->flush();
  960.             }
  961.         }
  962.         $domain_suffix '.' substr($request->server->get('SERVER_NAME'), 6);
  963.         $response $this->render('sign_up_process/step_company.html.twig', [
  964.             'controller' => $this,
  965.             'code' => $signUpProcess->getCode(),
  966.             'screen' => 'input-company',
  967.             'headersteps' => true,
  968.             'complete' => false,
  969.             'controller_name' => 'SignUpController',
  970.             'signUpProcess' => $signUpProcess,
  971.             'domain_suffix' => $domain_suffix,
  972.             'next' =>  $this->generateUrl($this->screensmap['input-servicearea']),
  973.             'previous' =>  $this->generateUrl($this->screensmap['input-login']),
  974.             'warningstatus' => 0,
  975.             'warningbody' => ''
  976.         ]);
  977.         return $response;
  978.     }
  979.     /**
  980.      * @Route("/sign/up/company/save", name="sign_up_company_save")
  981.      */
  982.     public function saveCompanySetup(Request $request): Response
  983.     {
  984.         $signUpProcess $this->checkSignUpProcess($request);
  985.         if ($signUpProcess == null) {
  986.             return new JsonResponse(
  987.                 ['message' => 'Sign up process not found'],
  988.                 Response::HTTP_NOT_FOUND,
  989.                 ['content-type' => 'application/json']
  990.             );
  991.         }
  992.         $result $this->doStepCompany($request$signUpProcess);
  993.         if (!$result) {
  994.             return new JsonResponse(
  995.                 ['message' => 'Setup Company Not Saved'],
  996.                 Response::HTTP_INTERNAL_SERVER_ERROR,
  997.                 ['content-type' => 'application/json']
  998.             );
  999.         }
  1000.         $signUpProcess $this->checkSignUpProcess($request);
  1001.         $data = [
  1002.             'confirmationCodeSent' => $signUpProcess->getConfirmationCodeSent(),
  1003.             'confirmationCodeVerified' => $signUpProcess->getConfirmationCodeVerified(),
  1004.         ];
  1005.         return new JsonResponse(
  1006.             [
  1007.                 'message' => 'Setup Company Saved',
  1008.                 'data' => $data
  1009.             ],
  1010.             Response::HTTP_OK,
  1011.             ['content-type' => 'application/json']
  1012.         );
  1013.     }
  1014.     /**
  1015.      * @Route("/sign/up/company/validateCode", name="sign_up_company_validate_code")
  1016.      */
  1017.     public function validateVerificationCode(Request $request): Response
  1018.     {
  1019.         $signUpProcess $this->checkSignUpProcess($request);
  1020.         if ($signUpProcess == null) {
  1021.             return new JsonResponse(
  1022.                 ['message' => 'Sign up process not found'],
  1023.                 Response::HTTP_NOT_FOUND,
  1024.                 ['content-type' => 'application/json']
  1025.             );
  1026.         }
  1027.         $now = new \DateTime();
  1028.         $verificationCode $request->query->get('verification_code');
  1029.         if ($now <= $signUpProcess->getConfirmationCodeExpireAt() && $verificationCode == $signUpProcess->getConfirmationCode()) {
  1030.             $signUpProcess->setConfirmationCodeVerified(true);
  1031.             $this->entityManager->persist($signUpProcess);
  1032.             $this->entityManager->flush();
  1033.             return new JsonResponse(
  1034.                 ['message' => 'Verification code OK'],
  1035.                 Response::HTTP_OK,
  1036.                 ['content-type' => 'application/json']
  1037.             );
  1038.         }
  1039.         return new JsonResponse(
  1040.             ['message' => 'Verification code does\'t match'],
  1041.             Response::HTTP_FORBIDDEN,
  1042.             ['content-type' => 'application/json']
  1043.         );
  1044.     }
  1045.     /**
  1046.      * @Route("/sign/up/company/sendCode", name="sign_up_company_send_code")
  1047.      */
  1048.     public function sendVerificationCode(Request $request): Response
  1049.     {
  1050.         $signUpProcess $this->checkSignUpProcess($request);
  1051.         if ($signUpProcess == null) {
  1052.             return new JsonResponse(
  1053.                 ['message' => 'Sign up process not found'],
  1054.                 Response::HTTP_NOT_FOUND,
  1055.                 ['content-type' => 'application/json']
  1056.             );
  1057.         }
  1058.         $phoneNumber $signUpProcess->getPhoneNumber();
  1059.         $code sprintf('%06d'rand(0999999));
  1060.         $now = new \DateTime();
  1061.         $codeExpireAt = clone $now;
  1062.         $codeExpireAt->modify('+2 minute');
  1063.         $signUpProcess->setUpdatedAt($now);
  1064.         $signUpProcess->setConfirmationCode($code);
  1065.         $signUpProcess->setConfirmationCodeExpireAt($codeExpireAt);
  1066.         $signUpProcess->setIpAddress($this->request->getClientIp());
  1067.         $signUpProcess->setConfirmationCodeSent(true);
  1068.         $signUpProcess->setConfirmationCodeVerified(false);
  1069.         $this->entityManager->persist($signUpProcess);
  1070.         $this->entityManager->flush();
  1071.         $smsSent $this->sendSMS($code$phoneNumber);
  1072.         if (!$smsSent) {
  1073.             return new JsonResponse(
  1074.                 ['message' => 'SMS not sent'],
  1075.                 Response::HTTP_INTERNAL_SERVER_ERROR,
  1076.                 ['content-type' => 'application/json']
  1077.             );
  1078.         }
  1079.         return new JsonResponse(
  1080.             [
  1081.                 'message' => 'SMS sent',
  1082.                 'code_expire_at' => $codeExpireAt->format(\DateTime::ATOM)
  1083.             ],
  1084.             Response::HTTP_OK,
  1085.             ['content-type' => 'application/json']
  1086.         );
  1087.     }
  1088.     private function sendSMS(string $codestring $phoneNumber): bool
  1089.     {
  1090.         $account_sid $this->getParameter('twilio_account_sid');
  1091.         $auth_token $this->getParameter('twilio_auth_token');
  1092.         $twilio_number $this->getParameter('twilio_number');
  1093.         $client = new TwilioClient($account_sid$auth_token);
  1094.         try {
  1095.             $message $client->messages->create(
  1096.                 $phoneNumber,
  1097.                 array(
  1098.                     'from' => $twilio_number,
  1099.                     'body' => 'Routezilla verification code: ' $code
  1100.                 )
  1101.             );
  1102.             if (in_array($message->status, ['sent''queued'])) {
  1103.                 return true;
  1104.             }
  1105.             return false;
  1106.         } catch (\Exception $e) {
  1107.             return false;
  1108.         }
  1109.     }
  1110.     /**
  1111.      * @Route("/sign/up/servicearea", name="sign_up_servicearea")
  1112.      */
  1113.     public function step_servicearea(Request $request): Response
  1114.     {
  1115.         $now = new \DateTime();
  1116.         $setCookie false;
  1117.         $signUpProcess $this->checkSignUpProcess($request);
  1118.         if ($signUpProcess == null) {
  1119.             return $this->redirect($this->generateUrl('sign_up_login'));
  1120.         } else {
  1121.             $o $this->redirectOnInvalidStep($signUpProcess'input-servicearea');
  1122.             if ($o != null) {
  1123.                 return $o;
  1124.             } else {
  1125.                 $signUpProcess->setScreen('input-servicearea');
  1126.                 $signUpProcess->setUpdatedAt($now);
  1127.                 $signUpProcess->setIpAddress($this->request->getClientIp());
  1128.                 $this->entityManager->persist($signUpProcess);
  1129.                 $this->entityManager->flush();
  1130.             }
  1131.         }
  1132.         return $this->render('sign_up_process/step_servicearea.html.twig', array(
  1133.             'controller' => $this,
  1134.             'code' => $signUpProcess->getCode(),
  1135.             'screen' => 'input-servicearea',
  1136.             'headersteps' => true,
  1137.             'complete' => false,
  1138.             'controller_name' => 'SignUpController',
  1139.             'signUpProcess' => $signUpProcess,
  1140.             'apiKey' => $this->getParameter('maps_api_key'),
  1141.             'next' =>  $this->generateUrl($this->screensmap['input-service']),
  1142.             'previous' =>  $this->generateUrl($this->screensmap['input-company']),
  1143.             'warningstatus' => 0,
  1144.             'warningbody' => ''
  1145.         ));
  1146.     }
  1147.     /**
  1148.      * @Route("/sign/up/service", name="sign_up_service")
  1149.      */
  1150.     public function step_service(Request $request): Response
  1151.     {
  1152.         $now = new \DateTime();
  1153.         $setCookie false;
  1154.         $signUpProcess $this->checkSignUpProcess($request);
  1155.         if ($signUpProcess == null) {
  1156.             return $this->redirect($this->generateUrl('sign_up_login'));
  1157.         } else {
  1158.             $o $this->redirectOnInvalidStep($signUpProcess'input-service');
  1159.             if ($o != null) {
  1160.                 return $o;
  1161.             } else {
  1162.                 $signUpProcess->setScreen('input-service');
  1163.                 $signUpProcess->setUpdatedAt($now);
  1164.                 $signUpProcess->setIpAddress($this->request->getClientIp());
  1165.                 $this->entityManager->persist($signUpProcess);
  1166.                 $this->entityManager->flush();
  1167.             }
  1168.         }
  1169.         return $this->render('sign_up_process/step_service.html.twig', array(
  1170.             'controller' => $this,
  1171.             'code' => $signUpProcess->getCode(),
  1172.             'screen' => 'input-service',
  1173.             'headersteps' => true,
  1174.             'complete' => false,
  1175.             'controller_name' => 'SignUpController',
  1176.             'signUpProcess' => $signUpProcess,
  1177.             'next' =>  $this->generateUrl($this->screensmap['complete']),
  1178.             'previous' =>  $this->generateUrl($this->screensmap['input-servicearea']),
  1179.             'displaywarning' => true,
  1180.             'warningstatus' => $signUpProcess != null && $signUpProcess->getWarningstatus() != null $signUpProcess->getWarningstatus() : 0,
  1181.             'warningbody' => $signUpProcess != null && $signUpProcess->getWarningbody() != null && $signUpProcess->getWarningbody() != '' json_decode($signUpProcess->getWarningbody()) : null,
  1182.         ));
  1183.     }
  1184.     /**
  1185.      * @Route("/sign/up/gbp", name="sign_up_gbp")
  1186.      */
  1187.     public function step_gbp(Request $request): Response
  1188.     {
  1189.         $now = new \DateTime();
  1190.         $setCookie false;
  1191.         $signUpProcess $this->checkSignUpProcess($request);
  1192.         if ($signUpProcess == null) {
  1193.             return $this->redirect($this->generateUrl('sign_up_login'));
  1194.         } else {
  1195.             $o $this->redirectOnInvalidStep($signUpProcess'input-service');
  1196.             if ($o != null) {
  1197.                 return $o;
  1198.             } else {
  1199.                 $signUpProcess->setScreen('input-service');
  1200.                 $signUpProcess->setUpdatedAt($now);
  1201.                 $signUpProcess->setIpAddress($this->request->getClientIp());
  1202.                 $this->entityManager->persist($signUpProcess);
  1203.                 $this->entityManager->flush();
  1204.             }
  1205.         }
  1206.         return $this->render('sign_up_process/step_gbp.html.twig', array(
  1207.             'controller' => $this,
  1208.             'code' => $signUpProcess->getCode(),
  1209.             'screen' => 'input-gbp',
  1210.             'headersteps' => true,
  1211.             'complete' => false,
  1212.             'controller_name' => 'SignUpController',
  1213.             'signUpProcess' => $signUpProcess,
  1214.             'next' =>  $this->generateUrl($this->screensmap['complete']),
  1215.             'previous' =>  $this->generateUrl($this->screensmap['input-servicearea']),
  1216.             'displaywarning' => true,
  1217.             'warningstatus' => $signUpProcess != null && $signUpProcess->getWarningstatus() != null $signUpProcess->getWarningstatus() : 0,
  1218.             'warningbody' => $signUpProcess != null && $signUpProcess->getWarningbody() != null && $signUpProcess->getWarningbody() != '' json_decode($signUpProcess->getWarningbody()) : null,
  1219.         ));
  1220.     }
  1221.     /**
  1222.      * @Route("/sign/up/commit", name="sign_up_commit")
  1223.      */
  1224.     public function step_commit(Request $request): Response
  1225.     {
  1226.         $now = new \DateTime();
  1227.         $setCookie false;
  1228.         $signUpProcess $this->checkSignUpProcess($request);
  1229.         if ($signUpProcess == null) {
  1230.             return $this->redirect($this->generateUrl('sign_up_login'));
  1231.         }
  1232.         $missingFields $this->validateMissingFields($signUpProcess);
  1233.         if ($missingFields) {
  1234.             return $this->redirect($this->generateUrl('sign_up_login'));
  1235.         }
  1236.         $signUpCode null;
  1237.         try {
  1238.             $o $this->validateSignupcode($request$signUpProcessfalse);
  1239.             if ($o === null) {
  1240.                 throw new \Exception("Unexpected error!");
  1241.             }
  1242.             if (!$o["valid"] ) {
  1243.                 throw new \Exception("Your sign up code is not valid anymore!");
  1244.             }
  1245.             $signUpCode $o["signUpCode"];
  1246.             $warningbody json_encode([
  1247.                 'code' => 0,
  1248.                 'message' => '',
  1249.                 'trace' => null
  1250.             ]);
  1251.             $signUpProcess->setWarningstatus(1);
  1252.             $signUpProcess->setWarningbody($warningbody);
  1253.             $signUpProcess->setUpdatedAt($now);
  1254.             $signUpProcess->setIpAddress($this->request->getClientIp());
  1255.             $this->entityManager->persist($signUpProcess);
  1256.             $this->entityManager->flush();
  1257.         } catch (\Throwable $throwable) {
  1258.             $warningbody json_encode([
  1259.                 'code' => $throwable->getCode(),
  1260.                 'line' => $throwable->getLine(),
  1261.                 'file' => $throwable->getFile(),
  1262.                 'message' => $throwable->getMessage(),
  1263.                 'trace' => $throwable->getTrace()
  1264.             ]);
  1265.             $signUpProcess->setWarningstatus(1);
  1266.             $signUpProcess->setWarningbody($warningbody);
  1267.             $signUpProcess->setUpdatedAt($now);
  1268.             $signUpProcess->setIpAddress($this->request->getClientIp());
  1269.             $this->entityManager->persist($signUpProcess);
  1270.             $this->entityManager->flush();
  1271.             return $this->redirect($this->generateUrl('sign_up_login'));
  1272.         }
  1273.         $o $this->redirectOnInvalidStep($signUpProcess'commit');
  1274.         if ($o != null) {
  1275.             return $o;
  1276.         } else {
  1277.             $signUpProcess->setScreen('commit');
  1278.             $signUpProcess->setUpdatedAt($now);
  1279.             $signUpProcess->setIpAddress($this->request->getClientIp());
  1280.             $this->entityManager->persist($signUpProcess);
  1281.             $this->entityManager->flush();
  1282.         }
  1283.         $b $this->doStepCommit($request$signUpProcess);
  1284.         //dd($b);
  1285.         if ($b != null) {
  1286.             $this->setGoToScreenOnSignUpProcess($signUpProcess'complete');
  1287.             $this->doStepComplete($request$signUpProcess);
  1288.             $response $this->guardAuthenticationHandler->authenticateUserAndHandleSuccess(
  1289.                 $b['user'],
  1290.                 $request,
  1291.                 $this->loginFormAuthenticator,
  1292.                 'main'
  1293.             );
  1294.             // $response = $this->render('sign_up_process/step_complete.html.twig', array(
  1295.             //     'code' => $signUpProcess->getCode(),
  1296.             //     'signUpProcess' => $signUpProcess
  1297.             // ));
  1298.             $this->unsetCookie($response);
  1299.         } else {
  1300.             $response = new Response(
  1301.                 'COMMIT FAILED',
  1302.                 Response::HTTP_OK,
  1303.                 ['content-type' => 'text/html']
  1304.             );
  1305.         }
  1306.         return $response;
  1307.     }
  1308.     private function validateSignupcode($request$signUpProcess$markvalidation true) {
  1309.         $now = new \DateTime();
  1310.         
  1311.         if ($markvalidation) {
  1312.             $signupcode $signUpProcess->getSignupcode();
  1313.         } else {
  1314.             $signupcode $request->request->get('signupcode');
  1315.             if ($signupcode === null || $signupcode === '') {
  1316.                 $signupcode $request->query->get('signupcode');
  1317.             }
  1318.         }
  1319.         if ($signupcode !== null && $signupcode !== '') {
  1320.             $signUpCode $this->signUpCodeRepository->findOneBy(['code' => $signupcode]);
  1321.             if ($signUpCode == null) {
  1322.                 throw new \Exception("Coupon code not found!");
  1323.             }
  1324.             if ($signUpCode->getStatus() != 'new') {
  1325.                 throw new \Exception("This coupon has expired!");
  1326.             }
  1327.             if ($signUpCode->getMaxUsageCount() !== null) {
  1328.                 if ($signUpCode->getUsageCount() === null) {
  1329.                     $signUpCode->setUsageCount(0);
  1330.                 }
  1331.                 if ($signUpCode->getUsageCount() >= $signUpCode->getMaxUsageCount()) {
  1332.                     if ($markvalidation) {
  1333.                         $signUpCode->setStatus('validated');
  1334.                         if ($signUpCode->getValidatedAt() === null) {
  1335.                             $signUpCode->setValidatedAt($now);    
  1336.                         }
  1337.                         $this->entityManager->persist($signUpCode);
  1338.                         $this->entityManager->flush();
  1339.                     }
  1340.                     throw new \Exception("This coupon has expired!");
  1341.                 } else {
  1342.                     //if ($markvalidation) { dd(['signupcode' => $signupcode, 'signUpCode' => $signUpCode]); }
  1343.                     if ($markvalidation) {
  1344.                         $signUpCode->setUsageCount($signUpCode->getUsageCount() + 1);
  1345.                         if ($signUpCode->getUsageCount() >= $signUpCode->getMaxUsageCount()) {
  1346.                             $signUpCode->setStatus('validated');
  1347.                             $signUpCode->setValidatedAt($now);
  1348.                         }
  1349.                         $this->entityManager->persist($signUpCode);
  1350.                         $this->entityManager->flush();
  1351.                     }
  1352.                 }
  1353.             } else {
  1354.                 if ($signUpCode->getUsageCount() + >= $signUpCode->getMaxUsageCount()) {
  1355.                     if ($markvalidation) {
  1356.                         $signUpCode->setUsageCount($signUpCode->getUsageCount() + 1);
  1357.                         //$signUpCode->setStatus('validated');
  1358.                         //$signUpCode->setValidatedAt($now);
  1359.                         $this->entityManager->persist($signUpCode);
  1360.                         $this->entityManager->flush();
  1361.                     }
  1362.                 }
  1363.             }
  1364.             return [
  1365.                 "valid" => true,
  1366.                 "coupon" => $signupcode,
  1367.                 "signUpCode" =>$signUpCode
  1368.             ];
  1369.         } else {
  1370.             return [
  1371.                 "valid" => true,
  1372.                 "coupon" => $signupcode,
  1373.                 "signUpCode" => null
  1374.             ];
  1375.         }
  1376.     }
  1377.     private function validateMissingFields($signUpProcess): bool
  1378.     {
  1379.         $methods = ['getEmail''getPassword''getConfirmPassword''getCompanyName''getPhoneNumber''getSchedulingWebsite''getLocationText''getNameOfService''getTimeRequired'];
  1380.         foreach ($methods as $method) {
  1381.             if (!$signUpProcess->$method()) {
  1382.                 return true;
  1383.             }
  1384.         }
  1385.         return false;
  1386.     }
  1387.     /**
  1388.      * @Route("/sign/up/complete", name="sign_up_complete")
  1389.      */
  1390.     public function step_complete(Request $request): Response
  1391.     {
  1392.         $now = new \DateTime();
  1393.         $setCookie false;
  1394.         $signUpProcess $this->checkSignUpProcess($request);
  1395.         if ($signUpProcess == null) {
  1396.             return $this->redirect($this->generateUrl('sign_up_login'));
  1397.         } else {
  1398.             $o $this->redirectOnInvalidStep($signUpProcess'complete');
  1399.             if ($o != null) {
  1400.                 return $o;
  1401.             } else {
  1402.                 $signUpProcess->setScreen('complete');
  1403.                 $signUpProcess->setUpdatedAt($now);
  1404.                 $signUpProcess->setIpAddress($this->request->getClientIp());
  1405.                 $this->entityManager->persist($signUpProcess);
  1406.                 $this->entityManager->flush();
  1407.             }
  1408.         }
  1409.         $response $this->render('sign_up_process/step_complete.html.twig', array(
  1410.             'controller' => $this,
  1411.             'code' => $signUpProcess->getCode(),
  1412.             'signUpProcess' => $signUpProcess
  1413.         ));
  1414.         $this->unsetCookie($response);
  1415.         return $response;
  1416.     }
  1417.     /**
  1418.      * @Route("/sign/up/checkdomain", name="sign_up_checkdomain")
  1419.      */
  1420.     public function checkdomain(Request $request): Response
  1421.     {
  1422.         $currentSignUpProcess $this->checkSignUpProcess($request);
  1423.         $prefix $request->request->get('prefix');
  1424.         if ($prefix == null) {
  1425.             $prefix $request->query->get('prefix');
  1426.         }
  1427.         $domain_suffix '.' substr($request->server->get('SERVER_NAME'), 6);
  1428.         $domain "$prefix$domain_suffix";
  1429.         $clientRepository $this->entityManager->getRepository(Client::class);
  1430.         $client $clientRepository->findOneByDomain($domain);
  1431.         $result true;
  1432.         if ($client != null) {
  1433.             $result true;
  1434.         } else {
  1435.             $signUpProcess $this->signUpProcessRepository->findOneBy(['status' => 'form''scheduling_website_full' => $domain]);
  1436.             if ($signUpProcess != null && $signUpProcess->getCode() != $currentSignUpProcess->getCode()) {
  1437.                 $result true;
  1438.             } else {
  1439.                 $result false;
  1440.             }
  1441.         }
  1442.         $response = new JsonResponse(
  1443.             $result,
  1444.             Response::HTTP_OK,
  1445.             ['content-type' => 'application/json']
  1446.         );
  1447.         return $response;
  1448.     }
  1449.     private function generateRandomString($length 10) {
  1450.         $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1451.         $charactersLength strlen($characters);
  1452.         $randomString '';
  1453.         for ($i 0$i $length$i++) {
  1454.             $randomString .= $characters[random_int(0$charactersLength 1)];
  1455.         }
  1456.         return $randomString;
  1457.     }
  1458.     /**
  1459.      * @Route("/sign/up/generatecodes/{num}/{len}", name="sign_up_generatecodes")
  1460.      */
  1461.     public function generatecodes(Request $requestint $numint $len): Response
  1462.     {
  1463.         $now = new \DateTime();
  1464.         for ($i 0$i $num$i++) {
  1465.             $code $this->generateRandomString($len);
  1466.             $signUpCode = new SignUpCode();
  1467.             $signUpCode->setStatus('new');
  1468.             $signUpCode->setCode($code);
  1469.             $signUpCode->setCreatedAt($now);
  1470.             $signUpCode->setCreatedAt($now);
  1471.             $this->entityManager->persist($signUpCode);
  1472.         }
  1473.         $this->entityManager->flush();
  1474.         $response = new JsonResponse(
  1475.             "OK",
  1476.             Response::HTTP_OK,
  1477.             ['content-type' => 'application/json']
  1478.         );
  1479.         
  1480.         return $response;
  1481.     }
  1482.     /**
  1483.      * @Route("/sign/up/checkemail", name="sign_up_checkemail")
  1484.      */
  1485.     public function checkemail(Request $request): Response
  1486.     {
  1487.         $currentSignUpProcess $this->checkSignUpProcess($request);
  1488.         $email $request->request->get('email');
  1489.         if ($email == null) {
  1490.             $email $request->query->get('email');
  1491.         }
  1492.         $domain_suffix '.' substr($request->server->get('SERVER_NAME'), 6);
  1493.         $userRepository $this->entityManager->getRepository(User::class);
  1494.         $user $userRepository->findOneByEmail($email);
  1495.         $result true;
  1496.         if ($user != null) {
  1497.             $result true;
  1498.         } else {
  1499.             $signUpProcess $this->signUpProcessRepository->findOneBy(['status' => 'form''email' => $email]);
  1500.             if ($signUpProcess != null && $signUpProcess->getCode() != $currentSignUpProcess->getCode()) {
  1501.                 $result true;
  1502.             } else {
  1503.                 $result false;
  1504.             }
  1505.         }
  1506.         $response = new JsonResponse(
  1507.             $result,
  1508.             Response::HTTP_OK,
  1509.             ['content-type' => 'application/json']
  1510.         );
  1511.         return $response;
  1512.     }
  1513.     /**
  1514.      * @Route("/sign/up/start", name="sign_up_start")
  1515.      */
  1516.     public function start(Request $request): Response
  1517.     {
  1518.         $mobile_detect = new Mobile_Detect();
  1519.         $redirect_uri $request->query->get('redirect_uri');
  1520.         $redirect_qparm $redirect_uri == null '' :  '?redirect_uri=' urlencode($redirect_uri);
  1521.         if ($mobile_detect->isMobile()) {
  1522.             return $this->redirect($request->getSchemeAndHttpHost() . $this->getParameter("signup_path_mobile") . $redirect_qparm);
  1523.         } else {
  1524.             return $this->redirect($request->getSchemeAndHttpHost() . $this->getParameter("signup_path") . $redirect_qparm);
  1525.         }
  1526.     }
  1527.     public function getEnvType() {
  1528.         $domain $this->request->getSchemeAndHttpHost();
  1529.         if (preg_match('/^[^:]+:\/\/[^\.]+\.routezilla\.com/'$domain$output_array)) {
  1530.             return 'production';
  1531.         } else if (preg_match('/^[^:]+:\/\/[^\.]+\.test.upgrade.routezilla\.com/'$domain$output_array)) {
  1532.             return 'staging';
  1533.         } else if (preg_match('/^[^:]+:\/\/[^\.]+\.staging.routezilla\.com/'$domain$output_array)) {
  1534.             return 'staging';
  1535.         } else if (preg_match('/^[^:]+:\/\/[^\.]+\.dev.routezilla\.com/'$domain$output_array)) {
  1536.             return 'development';
  1537.         } else {
  1538.             return 'local';
  1539.         }
  1540.         
  1541.     }
  1542.     /**
  1543.      * @Route("/sign/up/test", name="sign_up_test")
  1544.      */
  1545.     public function test(Request $request): Response
  1546.     {
  1547.         // Your Account SID and Auth Token from twilio.com/console
  1548.         //$account_sid = 'AC9abc2cfa0bd339976d41715a953a37c8';
  1549.         //$auth_token = '8c32a440651eb070edc7a2c9eaf1eddf';
  1550.         // In production, these should be environment variables. E.g.:
  1551.         // $auth_token = $_ENV["TWILIO_AUTH_TOKEN"]
  1552.         $account_sid $this->getParameter('twilio_account_sid');
  1553.         $auth_token $this->getParameter('twilio_auth_token');
  1554.         // A Twilio number you own with SMS capabilities
  1555.         //$twilio_number = "+19402408415";
  1556.         $twilio_number $this->getParameter('twilio_number');
  1557.         $client = new TwilioClient($account_sid$auth_token);
  1558.         $resp $client->messages->create(
  1559.             // Where to send a text message (your cell phone?)
  1560.             //'+16048077923',
  1561.             '+5585997147777',
  1562.             array(
  1563.                 'from' => $twilio_number,
  1564.                 'body' => 'Pedro: I sent this message in under 10 minutes!'
  1565.             )
  1566.         );
  1567.         dd($resp);
  1568.     }
  1569.     /** 
  1570.      * @Route("/clientredirect/{prefix}", name="sign_up_client_redirect") 
  1571.      */
  1572.     public function client_redirect(Request $request$prefix) {
  1573.         //$via = $request->query->get('via');
  1574.         $a_server explode('.'$request->server->get('SERVER_NAME'));
  1575.         array_splice($a_server01);
  1576.         $saddress sprintf('%s://%s.%s/dashboard?ic_track_event=client-onboarding-survey-completed'$request->getScheme(), $prefiximplode('.'$a_server));
  1577.         return $this->redirect($saddress);
  1578.     }
  1579. }