src/Controller/Tenants/Tenant1/SignUpController.php line 99

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Tenants\Tenant1;
  3. use App\Controller\Traits\SecurityTrait;
  4. use App\Exception\reCaptcha3Exception;
  5. use App\Services\reCaptcha3ValidatorService;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
  9. use App\Services\{
  10.     EntityServices\UserEntityService,
  11.     ParameterService,
  12.     Stripe\StripeService,
  13.     TenantService,
  14.     TranslatorService,
  15.     TenantFlowService
  16. };
  17. use App\Entity\{
  18.     SubscriptionParameters,
  19.     User
  20. };
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Component\Security\Core\Security;
  25. class SignUpController extends AbstractController
  26. {
  27.     use SecurityTrait;
  28.     private $reCaptcha3ValidatorService;
  29.     private $stripeService;
  30.     private $userEntityService;
  31.     public function __construct(
  32.         StripeService $stripeService,
  33.         TenantService $tenantService,
  34.         TenantFlowService $tenantFlowService,
  35.         UserEntityService $userEntityService,
  36.         reCaptcha3ValidatorService $reCaptcha3ValidatorService,
  37.         ParameterService $parameterService
  38.     )
  39.     {
  40.         $this->stripeService $stripeService->setSDK('tenant1');
  41.         $this->tenant $tenantService->defineTenant();
  42.         $this->tenantFlowService $tenantFlowService;
  43.         $this->userEntityService $userEntityService;
  44.         $this->reCaptcha3ValidatorService $reCaptcha3ValidatorService;
  45.         $this->reCaptcha3ValidatorService->setAccess(
  46.             $parameterService->getParameter($this->tenant->getSettingsArrayAssoc()['config'] ?? 'non-existent''reCaptcha3.secretKey'),
  47.             $parameterService->getParameter($this->tenant->getSettingsArrayAssoc()['config'] ?? 'non-existent''reCaptcha3.allowableScore')
  48.         );
  49.     }
  50.     /**
  51.      * @Route("/sign-up", name="sign_up")
  52.      */
  53.     public function signUp(Request $requestSecurity $security): Response
  54.     {
  55.         if (!is_null($security->getUser())) return $this->redirectToRoute('user_profile');
  56.         return $this->render("{$this->tenant->getRootPath()}/pages/sign-up.html.twig", [
  57.                 'rootPath' => $this->tenant->getRootPath(),
  58.                 'userFields' => $this->tenant->getUserFieldsArray(),
  59.                 'message' => $errorMessage ?? '',
  60.             ]
  61.             + $this->tenantFlowService->prepareTemplateArguments('signUp'$this->tenant)
  62.             + $this->tenantFlowService->prepareTemplateArguments('menu'$this->tenant)
  63.         );
  64.     }
  65.     /**
  66.      * @Route("/sign-up-press", name="sign_up_press")
  67.      */
  68.     public function signUpPress(Request $requestSecurity $security): Response
  69.     {
  70.         $user $security->getUser();
  71.         if (
  72.             ($user instanceof User)
  73.             &&
  74.             array_key_exists('pressPlusStatus'$user->getFieldsArrayAssoc())
  75.             &&
  76.             $user->getFieldsArrayAssoc()['pressPlusStatus'] == 'Active'
  77.         ) return $this->redirectToRoute('user_profile');
  78.         return $this->render("{$this->tenant->getRootPath()}/pages/sign-up-press.html.twig", [
  79.                 'user' => $user,
  80.                 'rootPath' => $this->tenant->getRootPath(),
  81.                 'userFields' => $this->tenant->getUserFieldsArray(),
  82.                 'message' => $errorMessage ?? '',
  83.             ]
  84.             + $this->tenantFlowService->prepareTemplateArguments('signUp'$this->tenant)
  85.             + $this->tenantFlowService->prepareTemplateArguments('menu'$this->tenant)
  86.         );
  87.     }
  88.     /**
  89.      * @Route("/sign-up-premium", name="sign_up_premium")
  90.      */
  91.     public function signUpPremium(Request $requestSecurity $security): Response
  92.     {
  93.         if (!is_null($security->getUser())) return $this->redirectToRoute('user_profile');
  94.         return $this->render("{$this->tenant->getRootPath()}/pages/sign-up-premium.html.twig", [
  95.                 'rootPath' => $this->tenant->getRootPath(),
  96.                 'userFields' => $this->tenant->getUserFieldsArray(),
  97.                 'message' => $errorMessage ?? '',
  98.             ]
  99.             + $this->tenantFlowService->prepareTemplateArguments('signUp'$this->tenant)
  100.             + $this->tenantFlowService->prepareTemplateArguments('frequency'$this->tenant)
  101.             + $this->tenantFlowService->prepareTemplateArguments('stripe'$this->tenant)
  102.             + $this->tenantFlowService->prepareTemplateArguments('menu'$this->tenant)
  103.         );
  104.     }
  105.     /**
  106.      * @Route("/sign-up-society", name="sign_up_society")
  107.      */
  108.     public function signUpSociety(Request $requestSecurity $security): Response
  109.     {
  110.         if (!is_null($security->getUser())) return $this->redirectToRoute('user_profile');
  111.         return $this->render("{$this->tenant->getRootPath()}/pages/sign-up-society.html.twig", [
  112.                 'rootPath' => $this->tenant->getRootPath(),
  113.                 'userFields' => $this->tenant->getUserFieldsArray(),
  114.                 'message' => $errorMessage ?? '',
  115.             ]
  116.             + $this->tenantFlowService->prepareTemplateArguments('signUp'$this->tenant)
  117.             + $this->tenantFlowService->prepareTemplateArguments('frequency'$this->tenant)
  118.             + $this->tenantFlowService->prepareTemplateArguments('stripe'$this->tenant)
  119.             + $this->tenantFlowService->prepareTemplateArguments('menu'$this->tenant)
  120.             + $this->tenantFlowService->prepareTemplateArguments('societies'$this->tenant)
  121.         );
  122.     }
  123.     /**
  124.      * @Route("/become-premium", name="become_premium")
  125.      */
  126.     public function becomePremium(Request $requestSecurity $security): Response
  127.     {
  128.         $user $security->getUser();
  129.         if ( ! ($user instanceof User) ) {
  130.             return $this->redirectToRoute('sign_up_premium');
  131.         }
  132.         if ( ! ($user->isRegistered()) ) {
  133.             return $this->redirectToRoute('user_profile');
  134.         }
  135.         return $this->render("{$this->tenant->getRootPath()}/pages/become-premium.html.twig", [
  136.                 'rootPath' => $this->tenant->getRootPath(),
  137.                 'userFields' => $this->tenant->getUserFieldsArray(),
  138.                 'message' => $errorMessage ?? '',
  139.             ]
  140.             + $this->tenantFlowService->prepareTemplateArguments('signUp'$this->tenant)
  141.             + $this->tenantFlowService->prepareTemplateArguments('frequency'$this->tenant)
  142.             + $this->tenantFlowService->prepareTemplateArguments('stripe'$this->tenant)
  143.             + $this->tenantFlowService->prepareTemplateArguments('menu'$this->tenant)
  144.         );
  145.     }
  146. }