Browse Source

add captcha

develop
Simon Vieille 4 weeks ago
parent
commit
eedfb4c9f2
Signed by: deblan
GPG Key ID: 579388D585F70417
  1. 29
      assets/css/app.scss
  2. 1
      composer.json
  3. 1
      config/bundles.php
  4. 14
      src/Form/Blog/UserCommentType.php
  5. 14
      src/Form/ContactType.php
  6. 4
      templates/page/contact/default.html.twig
  7. 5
      templates/page/post/_post.html.twig

29
assets/css/app.scss

@ -109,6 +109,35 @@ pre[class*="language-"] {
textarea {
border-radius: 10px;
}
&-captcha {
label {
display: block;
}
img {
vertical-align: middle;
margin-right: 10px;
border-radius: 10px;
width: auto;
}
input {
display: inline-block;
width: 100px !important;
height: 50px !important;
margin-bottom: -1px;
}
.form-error-icon {
display: none;
}
.form-error-message {
display: block;
color: red;
}
}
}
.button, .btn, input[type="submit"], input[type="button"] {

1
composer.json

@ -7,6 +7,7 @@
"php": ">=8.0.0",
"beberlei/doctrineextensions": "^1.3",
"friendsofsymfony/jsrouting-bundle": "^2.7",
"gregwar/captcha-bundle": "^2.2",
"knplabs/knp-markdown-bundle": "^1.9",
"knplabs/knp-menu-bundle": "^3.1",
"murph/murph-core": "dev-master"

1
config/bundles.php

@ -24,4 +24,5 @@ return [
Knp\DoctrineBehaviors\DoctrineBehaviorsBundle::class => ['all' => true],
SPE\FilesizeExtensionBundle\SPEFilesizeExtensionBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Gregwar\CaptchaBundle\GregwarCaptchaBundle::class => ['all' => true],
];

14
src/Form/Blog/UserCommentType.php

@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Url;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Gregwar\CaptchaBundle\Type\CaptchaType;
class UserCommentType extends AbstractType
{
@ -86,6 +87,19 @@ class UserCommentType extends AbstractType
]
);
$builder->add(
'captcha',
CaptchaType::class,
[
'invalid_message' => 'Code invalide',
'label' => 'Captcha',
'max_front_lines' => 1,
'width' => 140,
'height' => 50,
'length' => 3,
]
);
$builder->add(
'parentCommentId',
HiddenType::class,

14
src/Form/ContactType.php

@ -10,6 +10,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Gregwar\CaptchaBundle\Type\CaptchaType;
class ContactType extends AbstractType
{
@ -71,6 +72,19 @@ class ContactType extends AbstractType
],
]
);
$builder->add(
'captcha',
CaptchaType::class,
[
'invalid_message' => 'Code invalide',
'label' => 'Captcha',
'max_front_lines' => 1,
'width' => 140,
'height' => 50,
'length' => 3,
]
);
}
public function configureOptions(OptionsResolver $resolver)

4
templates/page/contact/default.html.twig

@ -36,6 +36,10 @@
{{ form_errors(form.message) }}
{{ form_widget(form.message, {attr: {cols: 30, rows: 10}}) }}
</div>
<div class="field field-captcha">
{{ form_label(form.captcha) }}
{{ form_widget(form.captcha) }}
</div>
<div class="field">
<input type="checkbox" id="rgpd" required>
<label for="rgpd">En validant ce formulaire, vous acceptez que j'utilise votre e-mail pour vous fournir une réponse.</label>

5
templates/page/post/_post.html.twig

@ -180,7 +180,10 @@
</div>
</div>
</div>
<div class="field field-captcha">
{{ form_label(form.captcha) }}
{{ form_widget(form.captcha) }}
</div>
<div class="field">
<input type="checkbox" id="rgpd" required>
<label for="rgpd">En validant ce formulaire, vous acceptez que les données saisies seront publiées sur cette page à l'exception de votre e-mail. Votre e-mail sera utilisé pour afficher votre avatar (<a href="https://www.libravatar.org/" target="_blank">via Libravatar</a>) et pour les notifications.</label>

Loading…
Cancel
Save