diff --git a/app/config/config.yml b/app/config/config.yml index 804aaaa..23872a5 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -29,6 +29,8 @@ framework: twig: debug: "%kernel.debug%" strict_variables: "%kernel.debug%" + form_themes: + - 'SkobkinCopyPasteBundle:Form:fields.html.twig' # Assetic Configuration assetic: diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Controller/CopypasteController.php b/src/Skobkin/Bundle/CopyPasteBundle/Controller/CopypasteController.php index c815ffd..289baed 100644 --- a/src/Skobkin/Bundle/CopyPasteBundle/Controller/CopypasteController.php +++ b/src/Skobkin/Bundle/CopyPasteBundle/Controller/CopypasteController.php @@ -30,6 +30,12 @@ class CopypasteController extends Controller $form->handleRequest($request); if ($form->isValid()) { + // Check "captcha" + // @todo check internally in transformation or somewhere else + if (null === $form->get('captcha')->getData()) { + throw $this->createNotFoundException('This isn\'t the service you\'re spamming to.'); + } + $em = $this->getDoctrine()->getManager(); if ($form->get('private')->getData()) { @@ -57,7 +63,7 @@ class CopypasteController extends Controller } } - throw new $this->createAccessDeniedException('Sorry :('); + throw $this->createAccessDeniedException('Sorry :('); } /** diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Form/CopypasteType.php b/src/Skobkin/Bundle/CopyPasteBundle/Form/CopypasteType.php index c1d69a4..ba1788b 100644 --- a/src/Skobkin/Bundle/CopyPasteBundle/Form/CopypasteType.php +++ b/src/Skobkin/Bundle/CopyPasteBundle/Form/CopypasteType.php @@ -66,6 +66,10 @@ class CopypasteType extends AbstractType }, //'preferred_choices' => [] ]) + ->add('captcha', 'skobkin_fake_captcha', [ + 'mapped' => false, + 'required' => true, + ]) ->add('actions', 'form_actions') ; } diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Form/FakeCaptchaType.php b/src/Skobkin/Bundle/CopyPasteBundle/Form/FakeCaptchaType.php new file mode 100644 index 0000000..ba1383e --- /dev/null +++ b/src/Skobkin/Bundle/CopyPasteBundle/Form/FakeCaptchaType.php @@ -0,0 +1,32 @@ +setDefaults([ + 'label' => false, + ]); + } + + public function getParent() + { + return 'hidden'; + } + + public function getName() + { + return 'skobkin_fake_captcha'; + } +} diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Resources/config/services.yml b/src/Skobkin/Bundle/CopyPasteBundle/Resources/config/services.yml index a7278cd..c1a68cf 100644 --- a/src/Skobkin/Bundle/CopyPasteBundle/Resources/config/services.yml +++ b/src/Skobkin/Bundle/CopyPasteBundle/Resources/config/services.yml @@ -1,4 +1,5 @@ services: -# skobkin_copy_paste.example: -# class: Skobkin\Bundle\CopyPasteBundle\Example -# arguments: [@service_id, "plain_value", %parameter%] + copypaste.form.type.fake_captcha: + class: Skobkin\Bundle\CopyPasteBundle\Form\FakeCaptchaType + tags: + - { name: form.type, alias: skobkin_fake_captcha } \ No newline at end of file diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Resources/views/Form/fields.html.twig b/src/Skobkin/Bundle/CopyPasteBundle/Resources/views/Form/fields.html.twig new file mode 100644 index 0000000..bea7688 --- /dev/null +++ b/src/Skobkin/Bundle/CopyPasteBundle/Resources/views/Form/fields.html.twig @@ -0,0 +1,16 @@ +{% block skobkin_fake_captcha_widget %} + {% spaceless %} +
+ + {% endspaceless %} +{% endblock %} \ No newline at end of file