Explorar el Código

[Frontend] Captcha

feature/module_traiteur_v1
Guillaume hace 3 años
padre
commit
772aa182f8
Se han modificado 3 ficheros con 48 adiciones y 2 borrados
  1. +21
    -1
      ShopBundle/Form/Frontend/NewsletterType.php
  2. +11
    -0
      ShopBundle/Form/Frontend/RegistrationType.php
  3. +16
    -1
      ShopBundle/Services/Utils.php

+ 21
- 1
ShopBundle/Form/Frontend/NewsletterType.php Ver fichero

@@ -2,19 +2,39 @@

namespace Lc\ShopBundle\Form\Frontend;

use Lc\ShopBundle\Services\UtilsManager;
use Lc\ShopBundle\Validator\Constraints\UniqueEmailValidator;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\EqualTo;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotNull;

class NewsletterType extends AbstractType
{
protected $utils ;

public function __construct(UtilsManager $utilsManager)
{
$this->utils = $utilsManager->getUtils() ;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('email', EmailType::class, [
'label' => 'Renseignez votre adresse email :'
'label' => 'Renseignez votre adresse email :',
'constraints' => [
new Email(),
new NotNull()
]
]);

// captcha
$this->utils->addCaptchaType($builder);
}

public function configureOptions(OptionsResolver $resolver)

+ 11
- 0
ShopBundle/Form/Frontend/RegistrationType.php Ver fichero

@@ -3,6 +3,7 @@
namespace Lc\ShopBundle\Form\Frontend;

use FOS\UserBundle\Form\Type\RegistrationFormType as BaseRegistrationFormType;
use Lc\ShopBundle\Services\UtilsManager;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@@ -11,6 +12,13 @@ use Symfony\Component\Form\FormBuilderInterface;

class RegistrationType extends AbstractType
{
protected $utils ;

public function __construct(UtilsManager $utilsManager)
{
$this->utils = $utilsManager->getUtils() ;
}

public function getParent()
{
return BaseRegistrationFormType::class;
@@ -47,6 +55,9 @@ class RegistrationType extends AbstractType
'mapped' => false,
'translation_domain' => 'lcshop',
]);

// captcha
$this->utils->addCaptchaType($builder);
}



+ 16
- 1
ShopBundle/Services/Utils.php Ver fichero

@@ -24,9 +24,12 @@ use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Context\UserPointSaleInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpClient\HttplugClient;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Validator\Constraints\EqualTo;
use Symfony\Contracts\Translation\TranslatorInterface;

class Utils
@@ -542,6 +545,18 @@ class Utils
}



public function addCaptchaType(FormBuilderInterface $builder)
{
$builder->add('specialField', HiddenType::class, [
'data' => 0,
'mapped' => false,
'attr' => [
'class' => 'special-field'
],
'constraints' => [
new EqualTo(['value' => $this->parameterBag->get('app.captcha_value'), 'message' => 'Valeur incorrecte'])
],
]);
}

}

Cargando…
Cancelar
Guardar