Internal: Integrate Gregwar CaptchaBundle for enhanced security in contact form - refs BT#20920

pull/5429/head
christianbeeznst 2 years ago
parent aaefd6f666
commit f9b09ee2dc
  1. 1
      composer.json
  2. 1
      config/bundles.php
  3. 3
      config/routes.yaml
  4. 17
      src/CoreBundle/Form/ContactType.php
  5. 10
      src/CoreBundle/Resources/views/Contact/index.html.twig

@ -82,6 +82,7 @@
"friendsofsymfony/jsrouting-bundle": "*",
"graphp/algorithms": "~0.8",
"graphp/graphviz": "~0.2",
"gregwar/captcha-bundle": "^2.2",
"jbroadway/urlify": "~1.1",
"jeroendesloovere/vcard": "~1.7",
"jimmiw/php-time-ago": "~3.2",

@ -36,4 +36,5 @@ return [
Hautelook\AliceBundle\HautelookAliceBundle::class => ['dev' => true, 'test' => true],
Sonata\Exporter\Bridge\Symfony\SonataExporterBundle::class => ['all' => true],
Oh\GoogleMapFormTypeBundle\OhGoogleMapFormTypeBundle::class => ['all' => true],
Gregwar\CaptchaBundle\GregwarCaptchaBundle::class => ['all' => true],
];

@ -53,3 +53,6 @@ web_ajax:
web_main:
path: main/
gregwar_captcha_routing:
resource: "@GregwarCaptchaBundle/Resources/config/routing/routing.yml"

@ -18,6 +18,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
use Gregwar\CaptchaBundle\Type\CaptchaType;
/**
* @template-extends AbstractType<array>
@ -76,6 +77,22 @@ class ContactType extends AbstractType
new NotBlank(),
],
])
->add('captcha', CaptchaType::class, [
'label' => $this->translator->trans('Verification'),
'width' => 200,
'height' => 50,
'length' => 6,
'quality' => 90,
'distortion' => true,
'background_color' => [255, 255, 255],
'reload' => true,
'as_url' => true,
'attr' => [
'class' => 'captcha_image',
'placeholder' => $this->translator->trans('Type the letters'),
],
'invalid_message' => $this->translator->trans('The security code entered was incorrect.'),
])
->add('submit', SubmitType::class, [
'label' => $this->translator->trans('Send'),
'attr' => [

@ -4,13 +4,13 @@
{% block content %}
<section id="contact-us" class="py-8">
<div class="max-w-md mx-auto">
<div class="mx-auto w-full">
<h2 class="text-2xl font-semibold text-center mb-6">{{ "Contact Us"|get_lang }}</h2>
{{ form_start(form, {'attr': {'class': 'bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4'}}) }}
{% for message in app.flashes('success') %}
<div class="mb-4 bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative" role="alert">
<div class="alert alert-success">
{{ message }}
</div>
{% endfor %}
@ -54,6 +54,12 @@
{{ termsContent | raw }}
</div>
<div class="mb-4">
{{ form_label(form.captcha) }}
{{ form_widget(form.captcha) }}
{{ form_errors(form.captcha) }}
</div>
{{ form_end(form) }}
</div>
</section>

Loading…
Cancel
Save