<?php
namespace App\Controller\Front;
use App\Entity\Info;
use App\Entity\InfoLandSale;
use App\Exception\InvalidFileExtensionException;
use App\Exception\InvalidFileSizeException;
use App\Manager\InfoManager;
use App\Service\Referrals\Client as ReferralClient;
use App\Traits\ReferredToCRM;
use Twig\Environment;
use App\Interfaces\Em;
use App\Interfaces\Csfr;
use App\Traits\CmdTrait;
use App\Traits\CrmTrait;
use App\Traits\UtmTrait;
use App\Entity\FormQuote;
use App\Traits\AllowTrait;
use App\Entity\FormLandSale;
use App\Entity\FormReferred;
use App\Interfaces\ParamTwig;
use App\Manager\RegionManager;
use App\Traits\FormTokenTrait;
use App\Traits\SyncEmailTrait;
use App\Traits\FileUploadTrait;
use App\Entity\FormSubscription;
use App\Manager\InfoFormManager;
use App\Manager\LogQuoteManager;
use App\Manager\PropertyManager;
use App\Manager\FormQuoteManager;
use App\Manager\InfoContactManager;
use App\Manager\ThanksQuoteManager;
use App\Manager\FormLandSaleManager;
use App\Manager\FormReferredManager;
use App\Manager\InfoLandSaleManager;
use App\Manager\InfoReferredManager;
use App\Manager\ThanksLandSaleManager;
use App\Manager\ThanksReferredManager;
use App\Manager\FormSubscriptionManager;
use Doctrine\ORM\EntityManagerInterface;
use App\Manager\ThanksSubscriptionManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class FormController extends AbstractController implements ParamTwig, Csfr, Em
{
use CmdTrait;
use UtmTrait;
use FormTokenTrait;
use SyncEmailTrait;
use CrmTrait;
use FileUploadTrait;
use AllowTrait;
use ReferredToCRM;
protected array $locals = [];
private string $captcha_token_name = '__tokenRecaptcha';
private string $captcha_action_name = '__actionRecaptcha';
protected $sd_em;
protected $sd_validator;
public function __construct(EntityManagerInterface $em, ValidatorInterface $validator)
{
$this->sd_em = $em;
$this->sd_validator = $validator;
$this->locals['menu_active'] = '';
}
public function getEm(): EntityManagerInterface
{
return $this->sd_em;
}
public function getParam(): ParameterBagInterface
{
return $this->container->get('parameter_bag');
}
public function getTwig(): Environment
{
return $this->container->get('twig');
}
public function getCsrfManager(): CsrfTokenManagerInterface
{
return $this->container->get('security.csrf.token_manager');
}
public function sendBackgroundEmail($data)
{
$keys = [
'class' => 'c',
'id' => 'i',
'template' => 't',
'subject' => 'j',
'recipients' => 'r',
'file' => 'f',
'qlog' => 'k',
];
$this->executeCommand(
$this->formatCommand('app:send-common-email', $data, $keys)
);
return true;
}
public function sendQuoteEmail($data)
{
$keys = [
'id' => 'i',
'property' => 't',
];
$this->executeCommand(
$this->formatCommand('app:send-quote-email', $data, $keys)
);
return true;
}
public function sendReferredEmail($data)
{
$keys = [
'id' => 'i',
];
$this->executeCommand(
$this->formatCommand('app:send-referred-email', $data, $keys)
);
return true;
}
public function sendLeadCrms($data)
{
$keys = [
'id' => 'i',
'property' => 't',
'log' => 'l',
];
$this->executeCommand(
$this->formatCommand('app:send-lead-crms', $data, $keys)
);
return true;
}
#[Route(path: '/guardar-utms/', name: 'store_utms')]
public function storeUtmsAction(Request $request): JsonResponse
{
$cookie = $this->setUtmCookie($request);
if (!$cookie) {
return new JsonResponse(['success' => false]);
}
$response = new JsonResponse(['success' => true]);
$response->headers->setCookie($cookie);
return $response;
}
#[Route(path: '/contactanos/', name: 'contact', methods: ['GET'])]
#[Template('front/form/contact.html.twig')]
public function contactAction(Request $request, InfoContactManager $icmgr, PropertyManager $pmgr): array
{
$this->locals['home'] = $icmgr->find(1);
$this->locals['list_data'] = $pmgr->listContactOptions();
return $this->locals;
}
#[Route(path: '/guardar-lead/{slug}/', name: 'register_quote_lead', methods: ['POST'])]
public function registerLead($slug, Request $request, PropertyManager $pmgr, FormQuoteManager $fqmgr, InfoManager $imgr): JsonResponse
{
$response = [
'success' => false,
'id' => 0,
'errors' => '',
];
if (!$this->isValidCaptcha($request)) {
$response['errors'] = 'No se pudo validar la autenticidad del formulario.
Recargue la página e intente de nuevo';
$response['formData'] = $request->request->all();
$response['recaptchaResponse'] = false;
return new JsonResponse($response);
}
$property = $pmgr->loadBySlug($slug);
if (!$property) {
throw $this->createNotFoundException('No encontrado');
}
$data = $request->request->all();
$token = $data['__token'];
$lead_id = 0;
unset($data[$this->captcha_token_name]);
unset($data[$this->captcha_action_name]);
unset($data['__token']);
unset($data['acepto']);
if (!$this->validateToken($this->quote_intention, $token)) {
$response['errors'] = 'Token no válido';
return new JsonResponse($response);
}
$tmp = $fqmgr->findPreRegisteredLead($data['dni'], $property->getTitle(), $lead_id);
if ($tmp) {
$entity = $tmp;
} else {
$entity = $fqmgr->create();
}
/** @var FormQuote $entity */
$entity = $this->fillEntity($request, $entity, $data);
/** @var Info $info */
$info = $imgr->find(1);
if ($this->blockLead($entity->getEmail(), $entity->getPhone(), $info->getEmailBlacklist(), $info->getPhoneBlacklist())) {
$response = [
'success' => true,
'id' => -1,
'errors' => '',
];
return new JsonResponse($response);
}
if ($this->isQuoteLeadRegistered($entity, $property)) {
$response['errors'] = "{$entity->getName()} te has registrado con anterioridad en este proyecto.";
return new JsonResponse($response);
}
$entity->setPropertyType($property->getPropertyType()->getTitle());
$entity->setProgram($property->getProgram() ?: null);
$entity->setProperty($property->getTitle());
$entity->setLocation($property->getLocation()->getTitle());
$entity->setIsCompleted(false);
$entity->setLight('rojo');
$entity->setPropertyId($property->getId());
$errors = $this->validateEntity($entity);
if (!empty($errors)) {
$response['errors'] = $errors;
return new JsonResponse($response);
}
$fqmgr->save($entity);
$response = [
'success' => true,
'id' => $entity->getId(),
'errors' => '',
];
return new JsonResponse($response);
}
#[Route(path: '/cotizar/', name: 'quote', methods: ['POST'])]
public function quote(
Request $request,
PropertyManager $pmgr,
FormQuoteManager $fqmgr,
LogQuoteManager $lqmgr,
InfoFormManager $ifmgr,
InfoManager $imgr
): JsonResponse {
set_time_limit(1800);
$slug = $request->request->get('slug');
$response = [
'success' => false,
'url' => $this->generateUrl('property', ['slug' => $slug]),
'errors' => '',
];
$property = $pmgr->loadBySlug($slug);
if (!$property) {
throw $this->createNotFoundException('No encontrado');
}
$data = $request->request->all();
$token = $data['__token'];
$lead_id = $data['lead_id'];
$is_pin = !empty($data['code_pin']);
unset($data[$this->captcha_token_name]);
unset($data[$this->captcha_action_name]);
unset($data['__token']);
unset($data['slug']);
unset($data['code_pin']);
unset($data['acepto']);
unset($data['lead_id']);
if (!$this->validateToken($this->quote_intention, $token)) {
$response['errors'] = 'Token no válido';
return new JsonResponse($response);
}
$tmp = $fqmgr->findPreRegisteredLead($data['dni'], $property->getTitle(), $lead_id);
if ($tmp) {
$entity = $tmp;
} else {
$entity = $fqmgr->create();
}
/** @var FormQuote $entity */
$entity = $this->fillEntity($request, $entity, $data);
/** @var Info $info */
$info = $imgr->find(1);
if ($this->blockLead($entity->getEmail(), $entity->getPhone(), $info->getEmailBlacklist(), $info->getPhoneBlacklist())) {
$response = [
'success' => true,
'errors' => '',
'url' => $this->generateUrl('thanks_quote', [
'slug' => $property->getSlug(),
'name' => $entity->getName(),
'dni' => $entity->getDni(),
'id' => $entity->getId(),
'referred' => $this->generateUrl('property', ['slug' => $property->getSlug()]),
])
];
return new JsonResponse($response);
}
if ($this->isQuoteLeadRegistered($entity, $property)) {
$response['errors'] = "{$entity->getName()} te has registrado con anterioridad en este proyecto.";
return new JsonResponse($response);
}
$entity->setPropertyType($property->getPropertyType()->getTitle());
$entity->setProgram($property->getProgram() ?: null);
$entity->setProperty($property->getTitle());
$entity->setLocation($property->getLocation()->getTitle());
$entity->setPropertyId($property->getId());
$entity->setIsCompleted(true);
$color = $is_pin ? 'verde' : 'amarillo';
$entity->setLight($color);
$errors = $this->validateEntity($entity);
if (!empty($errors)) {
$response['errors'] = $errors;
return new JsonResponse($response);
}
$entity->setCreated(new \DateTime());
$fqmgr->save($entity);
$log = $lqmgr->create();
$log->setFormId($entity->getId());
$log->setFormFullName($entity->getName() . ' ' . $entity->getLastname());
$log->setFormDni($entity->getDni());
$log->setFormCreated($entity->getCreated());
$log->setProject($entity->getProperty());
$log->setEmailDateSend(new \DateTime());
$lqmgr->save($log);
$home = $ifmgr->find(1);
$rpta = $this->sendSDSyncEmail([
'data' => ['detalle' => $entity],
'recipients' => $property->getFormEmail() ?: $home->getQuoteEmail(),
'subject' => 'Los Portales Vivienda - Cotización',
'template' => 'front/mail/quote.html.twig',
'qlog' => $log,
'file' => false,
]);
if ($property->getLetSendCrm()) {
$this->executeSendLeadToCrms($log->getId(), $property->getId());
}
if ($property->getMailingShow()) {
$this->sendQuoteEmail([
'id' => $entity->getId(),
'property' => $property->getId()
]);
}
$session = $request->getSession();
$session->remove('pin_code');
return new JsonResponse([
'success' => true,
'errors' => '',
'url' => $this->generateUrl('thanks_quote', [
'slug' => $property->getSlug(),
'name' => $entity->getName(),
'dni' => $entity->getDni(),
'id' => $entity->getId(),
'referred' => $this->generateUrl('property', ['slug' => $property->getSlug()]),
])
]);
}
#[Route(path: '/enviar-lead-crm/', name: 'send_lead_crm', methods: ['GET'])]
public function sendLeadCrmAction(Request $request): JsonResponse
{
$rpta = $this->executeSendLeadToCrms(
$request->query->getInt('logid', 0),
$request->query->getInt('propertyid', 0)
);
return new JsonResponse($rpta);
}
#[Route(path: '/subscribirse/', name: 'subscribe', methods: ['POST'])]
public function subscribe(Request $request, FormSubscriptionManager $fsmgr, InfoFormManager $ifmgr): JsonResponse
{
$response = [
'success' => false,
'url' => $this->generateUrl('home'),
'errors' => '',
];
$data = $request->request->all();
$token = $data['__token'];
unset($data['__token']);
unset($data['acepto']);
if (!$this->validateToken($this->subscription_intention, $token)) {
$response['errors'] = 'Token no válido';
return new JsonResponse($response);
}
$entity = $fsmgr->create();
$entity = $this->fillEntity($request, $entity, $data);
$errors = $this->validateEntity($entity);
if (!empty($errors)) {
$response['errors'] = $errors;
return new JsonResponse($response);
}
$fsmgr->save($entity);
$home = $ifmgr->find(1);
$this->sendBackgroundEmail([
'class' => FormSubscription::class,
'id' => $entity->getId(),
'recipients' => $home->getSubscribeEmail(),
'subject' => 'Los Portales Vivienda - Subscripción',
'template' => 'front/mail/subscription.html.twig',
]);
return new JsonResponse([
'success' => true,
'errors' => '',
'url' => $this->generateUrl('thanks_subscription', [
'referred' => $this->generateUrl('home')
])
]);
}
#[Route(path: '/venta-terreno/', name: 'land_sale', methods: ['GET', 'POST'])]
public function landSaleAction(
Request $request,
InfoLandSaleManager $ilsmgr,
InfoFormManager $ifmgr,
RegionManager $rmgr,
FormLandSaleManager $flsmgr
): Response {
if (!$this->allowMenu('land_sale')) {
return $this->redirect($this->generateUrl('home'));
}
$intention = 'land_sale';
/** @var InfoLandSale $home */
$home = $ilsmgr->find(1);
$this->locals['home'] = $home;
$this->locals['info_form'] = $ifmgr->find(1);
$this->locals['regions'] = $rmgr->findBy(['active' => true]);
$this->locals['_token'] = $this->generateToken($intention);
if ($request->isMethod('post')) {
$data = $request->request->all();
$image = $request->files->get('land_image');
$plane = $request->files->get('land_plane');
$directory = 'terrenos';
$validImage = true;
$validPlane = true;
if ($image) {
try {
$this->isValidImage($image, $home->getImageSize() * 1024 * 1024, $home->getImageExts() ?? ['png', 'jpg', 'jpeg', 'pdf']);
} catch (InvalidFileExtensionException|InvalidFileSizeException $e) {
$validImage = false;
$errorMessage = $e->getMessage();
if ($e instanceof InvalidFileExtensionException and $home->getImageErrorExts()) {
$errorMessage = $home->getImageErrorExts();
} elseif ($e instanceof InvalidFileSizeException and $home->getImageErrorSize()) {
$errorMessage = $home->getImageErrorSize();
}
$this->addFlash('error_message_image', $errorMessage);
}
}
if ($plane) {
try {
$this->isValidImage($plane, $home->getPlaneSize() * 1024 * 1024, $home->getPlaneExts() ?? ['png', 'jpg', 'jpeg', 'pdf']);
} catch (InvalidFileExtensionException|InvalidFileSizeException $e) {
$validPlane = false;
$errorMessage = $e->getMessage();
if ($e instanceof InvalidFileExtensionException and $home->getPlaneErrorExts()) {
$errorMessage = $home->getPlaneErrorExts();
} elseif ($e instanceof InvalidFileSizeException and $home->getPlaneErrorSize()) {
$errorMessage = $home->getPlaneErrorSize();
}
$this->addFlash('error_message_plane', $errorMessage);
}
}
if (!$validImage or !$validPlane) {
return $this->redirectToRoute('land_sale');
}
if ($image and $validImage) {
$landImage = $this->uploadLandSaleImages($image, $directory);
$data['land_image'] = $landImage;
}
if ($plane and $validPlane) {
$planeImage = $this->uploadLandSaleImages($plane, $directory);
$data['land_plane'] = $planeImage;
}
$token = $data['__token'];
unset($data['__token']);
unset($data['acepto']);
if (!$this->validateToken($intention, $token)) {
return $this->redirectToRoute('land_sale');
}
$entity = $flsmgr->create();
$entity = $this->fillEntity($request, $entity, $data);
$errors = $this->validateEntity($entity);
if (!empty($errors)) {
return $this->redirectToRoute('land_sale');
}
$flsmgr->save($entity);
$this->sendBackgroundEmail([
'class' => FormLandSale::class,
'id' => $entity->getId(),
'recipients' => $this->locals['info_form']->getLandSaleEmail(),
'subject' => 'Los Portales Vivienda - Venta de Terreno',
'template' => 'front/mail/land_sale.html.twig',
]);
$this->sendBackgroundEmail([
'class' => FormLandSale::class,
'id' => $entity->getId(),
'recipients' => $entity->getEmail(),
'subject' => 'Los Portales Vivienda - Venta de Terreno',
'template' => 'front/mail/land_sale_client.html.twig',
]);
return $this->redirectToRoute('thanks_land_sale', [
'name' => $entity->getName(),
'dni' => $entity->getDni(),
'referred' => $this->generateUrl('land_sale')
]);
}
return $this->render("front/form/land_sale.html.twig", $this->locals);
}
#[Route(path: '/imprimir-pdf/', name: 'print_pdf', methods: ['POST'])]
public function printPdfAction(Request $request, FormReferredManager $frmgr, InfoReferredManager $irmgr): Response
{
$intention = 'referred';
$data = $request->request->all();
$token = $data['__token'];
unset($data['__token']);
unset($data['acepto']);
$response = [
'success' => false,
'errors' => '',
];
if (!$this->validateToken($intention, $token)) {
$response['errors'] = 'Token no válido';
return new JsonResponse($response);
}
$entity = $frmgr->create();
$entity = $this->fillEntity($request, $entity, $data);
$errors = $this->validateEntity($entity);
if (!empty($errors)) {
$response['errors'] = $errors;
return new JsonResponse($response);
}
$this->locals['home'] = $irmgr->find(1);
$this->locals['entity'] = $entity;
return $this->render("front/mail/_body_referred.html.twig", $this->locals);
}
#[Route(path: '/programa-de-referidos/', name: 'referred', methods: ['GET', 'POST'])]
public function referredAction(
Request $request,
InfoReferredManager $irmgr,
InfoFormManager $ifmgr,
FormReferredManager $frmgr
): Response {
if (!$this->allowMenu('referred')) {
return $this->redirect($this->generateUrl('home'));
}
$intention = 'referred';
$this->locals['home'] = $irmgr->find(1);
$this->locals['info_form'] = $ifmgr->find(1);
$this->locals['_token'] = $this->generateToken($intention);
if ($request->isMethod('post')) {
$response = [
'success' => false,
'url' => $this->generateUrl('referred'),
'errors' => '',
];
$data = $request->request->all();
$token = $data['__token'];
unset($data['__token']);
unset($data['acepto']);
if (!$this->validateToken($intention, $token)) {
$response['errors'] = 'Token no válido';
return new JsonResponse($response);
}
$entity = $frmgr->create();
/** @var FormReferred $entity */
$entity = $this->fillEntity($request, $entity, $data);
$session = $request->getSession();
/** @var ReferralClient $client */
$client = $session->get('sd_referral_client', new ReferralClient());
if (!$client->isValidClient()) {
$response['errors'] = 'No se obtuvieron datos del usuario';
return new JsonResponse($response);
}
$entity->setReferrerDni($client->getDocumentNumber());
$errors = $this->validateEntity($entity);
if (!empty($errors)) {
$response['errors'] = $errors;
return new JsonResponse($response);
}
$frmgr->save($entity);
$session->remove('sd_referral_client');
if ($this->locals['home']->isSendToCrm()) {
$this->sendReferredToCRM($entity);
}
$this->sendBackgroundEmail([
'class' => FormReferred::class,
'id' => $entity->getId(),
'recipients' => $this->locals['info_form']->getReferredEmail(),
'subject' => 'Los Portales Vivienda - Programa Referidos',
'template' => 'front/mail/referred.html.twig',
]);
$this->sendReferredEmail([
'id' => $entity->getId(),
]);
return new JsonResponse([
'success' => true,
'errors' => '',
'url' => $this->generateUrl('thanks_referred', [
'name' => $entity->getReferrerFullName(),
'dni' => $entity->getReferrerDni(),
'referred' => $this->generateUrl('referred')
])
]);
}
return $this->render("front/form/referred.html.twig", $this->locals);
}
#[Route(path: '/gracias-por-contactarnos/', name: 'thanks', methods: ['GET'])]
#[Route(path: '/gracias-por-contactarnos/{slug}/', name: 'thanks_quote', methods: ['GET'])]
#[Template('front/form/thanks_quote.html.twig')]
public function thanksQuoteAction(
Request $request,
PropertyManager $pmgr,
ThanksQuoteManager $tqmgr,
$slug = ''
): array {
$this->locals['user_name'] = $request->query->get('name', '');
$this->locals['referred'] = $request->query->get('referred', '');
$this->locals['lead_id'] = $request->query->get('id', '');
$this->locals['property'] = $pmgr->loadBySlug($slug);
$this->locals['home'] = $tqmgr->find(1);
return $this->locals;
}
#[Route(path: '/gracias-por-subscribirte/', name: 'thanks_subscription', methods: ['GET'])]
#[Template('front/form/thanks_subscription.html.twig')]
public function thanksSubscriptionAction(Request $request, ThanksSubscriptionManager $tsmgr): array
{
$this->locals['user_name'] = $request->query->get('name', '');
$this->locals['referred'] = $request->query->get('referred', '');
$this->locals['home'] = $tsmgr->find(1);
return $this->locals;
}
#[Route(path: '/gracias-por-referir/', name: 'thanks_referred', methods: ['GET'])]
#[Template('front/form/thanks_referred.html.twig')]
public function thanksReferredAction(Request $request, ThanksReferredManager $trmgr): array
{
$this->locals['user_name'] = $request->query->get('name', '');
$this->locals['referred'] = $request->query->get('referred', '');
$this->locals['home'] = $trmgr->find(1);
return $this->locals;
}
#[Route(path: '/gracias-por-escribirnos/', name: 'thanks_land_sale', methods: ['GET'])]
#[Template('front/form/thanks_land_sale.html.twig')]
public function thanksLandSaleAction(Request $request, ThanksLandSaleManager $tlsmgr): array
{
$this->locals['user_name'] = $request->query->get('name', '');
$this->locals['referred'] = $request->query->get('referred', '');
$this->locals['home'] = $tlsmgr->find(1);
return $this->locals;
}
#[Route(path: '/lead-from-code/', name: 'lead_from_code', methods: ['POST'])]
public function leadFromCodeAction(Request $request, FormQuoteManager $fqmgr): JsonResponse
{
$code = $request->request->getInt('idcontacto', 0);
$start = (int) $this->getParameter('inmobiliario_number');
$code = $code - $start;
if ($code < 1) {
return new JsonResponse([]);
}
$lead = $fqmgr->find($code);
if (!$lead) {
return new JsonResponse([]);
}
$data = [];
$keys = [
'name',
'lastname',
'email',
'dni',
'phone',
'schedule',
'property_type',
'program',
'location',
'property',
'utm_source',
'utm_medium',
'utm_campaign',
'utm_content',
'utm_term',
'gclid'
];
foreach ($keys as $key) {
$method = 'get' . $this->convertAttributeToMethod($key);
$data[$key] = $lead->$method();
}
return new JsonResponse($data);
}
private function validateEntity($entity): string
{
$errors = $this->sd_validator->validate($entity);
if ((is_countable($errors) ? count($errors) : 0) < 1) {
return '';
}
return (string) $errors;
}
private function fillEntity(Request $request, $entity, $data)
{
foreach ($data as $attr => $value) {
$method = 'set' . $this->convertAttributeToMethod($attr);
$entity->$method($value);
}
$entity = $this->fillUtmDataEntity($request, $entity);
return $entity;
}
private function fillUtmDataEntity(Request $request, $entity)
{
$cookie_data = $this->getUtmCookie($request);
foreach ($cookie_data as $key => $value) {
$method = 'set' . $this->convertAttributeToMethod($key);
$entity->$method($value);
}
return $entity;
}
private function convertAttributeToMethod($attribute): string
{
$tmp = explode('_', $attribute);
$tmp = array_map('ucwords', $tmp);
return implode('', $tmp);
}
private function isQuoteLeadRegistered($entity, $property): bool
{
$lead = $this
->getEm()
->getRepository(FormQuote::class)
->validRegistrationDate($entity->getDni(), $property)
;
return !is_null($lead);
}
private function blockLead(?string $email, ?string $phone, ?string $emailBlacklist, ?string $phoneBlacklist): bool
{
if (is_null($emailBlacklist) and is_null($phoneBlacklist)) {
return false;
}
$emailBlacklistList = preg_split("/\r\n|\n|\r/", $emailBlacklist);
$phoneBlacklistList = preg_split("/\r\n|\n|\r/", $phoneBlacklist);
if (is_null($email) and is_null($phone)) {
return true;
}
if (is_array($emailBlacklistList) and !empty($emailBlacklistList)) {
if (in_array($email, $emailBlacklistList)) {
return true;
}
}
if (is_array($phoneBlacklistList) and !empty($phoneBlacklistList)) {
if (in_array($phone, $phoneBlacklistList)) {
return true;
}
}
return false;
}
private function isValidCaptcha(Request $request): bool
{
$private_key = '6LfPOd8hAAAAABdYI7e-SczpNScS4cOlzes1g74F';
$remote_ip = $request->getClientIp();
$token_recaptcha = $request->request->get($this->captcha_token_name, '');
$action_recaptcha = $request->request->get($this->captcha_action_name, '');
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = [
'secret' => $private_key,
'response' => $token_recaptcha,
'remoteip' => $remote_ip,
'action' => $action_recaptcha,
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
]
];
$context = stream_context_create($options);
$gresponse = file_get_contents($url, false, $context);
$response = json_decode($gresponse, true, 512, JSON_THROW_ON_ERROR);
if (!(is_array($response) && array_key_exists('success', $response))) {
return false;
}
return (bool) $response['success'];
}
}