<?php
namespace App\Controller\Tenants\Tenant1;
use App\Controller\Traits\SecurityTrait;
use App\Exception\reCaptcha3Exception;
use App\Services\reCaptcha3ValidatorService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
use App\Services\{
EntityServices\UserEntityService,
ParameterService,
Stripe\StripeService,
TenantService,
TranslatorService,
TenantFlowService
};
use App\Entity\{
SubscriptionParameters,
User
};
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
class SignUpController extends AbstractController
{
use SecurityTrait;
private $reCaptcha3ValidatorService;
private $stripeService;
private $userEntityService;
public function __construct(
StripeService $stripeService,
TenantService $tenantService,
TenantFlowService $tenantFlowService,
UserEntityService $userEntityService,
reCaptcha3ValidatorService $reCaptcha3ValidatorService,
ParameterService $parameterService
)
{
$this->stripeService = $stripeService->setSDK('tenant1');
$this->tenant = $tenantService->defineTenant();
$this->tenantFlowService = $tenantFlowService;
$this->userEntityService = $userEntityService;
$this->reCaptcha3ValidatorService = $reCaptcha3ValidatorService;
$this->reCaptcha3ValidatorService->setAccess(
$parameterService->getParameter($this->tenant->getSettingsArrayAssoc()['config'] ?? 'non-existent', 'reCaptcha3.secretKey'),
$parameterService->getParameter($this->tenant->getSettingsArrayAssoc()['config'] ?? 'non-existent', 'reCaptcha3.allowableScore')
);
}
/**
* @Route("/sign-up", name="sign_up")
*/
public function signUp(Request $request, Security $security): Response
{
if (!is_null($security->getUser())) return $this->redirectToRoute('user_profile');
return $this->render("{$this->tenant->getRootPath()}/pages/sign-up.html.twig", [
'rootPath' => $this->tenant->getRootPath(),
'userFields' => $this->tenant->getUserFieldsArray(),
'message' => $errorMessage ?? '',
]
+ $this->tenantFlowService->prepareTemplateArguments('signUp', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('menu', $this->tenant)
);
}
/**
* @Route("/sign-up-press", name="sign_up_press")
*/
public function signUpPress(Request $request, Security $security): Response
{
$user = $security->getUser();
if (
($user instanceof User)
&&
array_key_exists('pressPlusStatus', $user->getFieldsArrayAssoc())
&&
$user->getFieldsArrayAssoc()['pressPlusStatus'] == 'Active'
) return $this->redirectToRoute('user_profile');
return $this->render("{$this->tenant->getRootPath()}/pages/sign-up-press.html.twig", [
'user' => $user,
'rootPath' => $this->tenant->getRootPath(),
'userFields' => $this->tenant->getUserFieldsArray(),
'message' => $errorMessage ?? '',
]
+ $this->tenantFlowService->prepareTemplateArguments('signUp', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('menu', $this->tenant)
);
}
/**
* @Route("/sign-up-premium", name="sign_up_premium")
*/
public function signUpPremium(Request $request, Security $security): Response
{
if (!is_null($security->getUser())) return $this->redirectToRoute('user_profile');
return $this->render("{$this->tenant->getRootPath()}/pages/sign-up-premium.html.twig", [
'rootPath' => $this->tenant->getRootPath(),
'userFields' => $this->tenant->getUserFieldsArray(),
'message' => $errorMessage ?? '',
]
+ $this->tenantFlowService->prepareTemplateArguments('signUp', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('frequency', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('stripe', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('menu', $this->tenant)
);
}
/**
* @Route("/sign-up-society", name="sign_up_society")
*/
public function signUpSociety(Request $request, Security $security): Response
{
if (!is_null($security->getUser())) return $this->redirectToRoute('user_profile');
return $this->render("{$this->tenant->getRootPath()}/pages/sign-up-society.html.twig", [
'rootPath' => $this->tenant->getRootPath(),
'userFields' => $this->tenant->getUserFieldsArray(),
'message' => $errorMessage ?? '',
]
+ $this->tenantFlowService->prepareTemplateArguments('signUp', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('frequency', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('stripe', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('menu', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('societies', $this->tenant)
);
}
/**
* @Route("/become-premium", name="become_premium")
*/
public function becomePremium(Request $request, Security $security): Response
{
$user = $security->getUser();
if ( ! ($user instanceof User) ) {
return $this->redirectToRoute('sign_up_premium');
}
if ( ! ($user->isRegistered()) ) {
return $this->redirectToRoute('user_profile');
}
return $this->render("{$this->tenant->getRootPath()}/pages/become-premium.html.twig", [
'rootPath' => $this->tenant->getRootPath(),
'userFields' => $this->tenant->getUserFieldsArray(),
'message' => $errorMessage ?? '',
]
+ $this->tenantFlowService->prepareTemplateArguments('signUp', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('frequency', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('stripe', $this->tenant)
+ $this->tenantFlowService->prepareTemplateArguments('menu', $this->tenant)
);
}
}