17 Commits

Author SHA1 Message Date
5778c54ae0 Add missing initialization 2022-02-09 10:19:13 +01:00
9b65966d27 update composer.json 2021-05-28 11:53:54 +02:00
633e30ae47 Add flow registration validation support 2021-05-28 08:08:42 +02:00
2f96c759ab Merge pull request #223 from Gemorroj/patch-1
php 8 support
2021-04-20 09:20:37 +02:00
2769e4791a php 8 support
#222
2021-04-18 12:06:03 +03:00
5e434e1859 gregwar/captcha version bump 2021-01-09 01:01:13 +01:00
df6915eb5e README details 2020-04-28 10:45:36 +02:00
b7685e63a1 README indentation 2020-04-28 10:44:39 +02:00
15bee25e9c Indentation in README 2020-04-28 10:43:03 +02:00
3a4e31473a Adding some note about session_key option for multiple captcha on same
page
2020-04-17 16:13:37 +02:00
fec0ebb2f1 Autowire controller 2020-04-09 10:18:10 +02:00
cdbe566acc Merge pull request #212 from l-vo/bundle_auto_registration
Fix flex auto-registration
2020-03-02 11:00:37 +01:00
93f9d3c1a7 Fix flex auto-registration 2020-02-29 20:31:09 +01:00
d4475118d0 Merge branch 'master' of github.com:Gregwar/CaptchaBundle 2020-01-14 11:15:40 +01:00
b8a129fc2a Adding controller class in services.yml 2020-01-14 11:14:42 +01:00
fe4b0dea2b Merge pull request #210 from alexander-schranz/patch-1
Fix compatibility table
2020-01-14 10:06:23 +01:00
640acadeea Fix compatibility table 2020-01-13 18:35:47 +01:00
5 changed files with 74 additions and 43 deletions

View File

@ -12,10 +12,10 @@ Compatibility with Symfony
==========================
| CaptchaBundle | Symfony | PHP |
|:---------------:|:---------:|:-------:|
| 3.* | 4.* - 5.* | 7.1 > |
| 2.* | 2.8 - 3.* | 5.3.9 > |
| 1.* | 2.1 - 2.7 | 5.3.0 > |
|:---------------:|:---------:|:--------:|
| 2.1.* | 4.* - 5.* | >= 7.1 |
| 2.0.* | 2.8 - 3.* | >= 5.3.9 |
| 1.* | 2.1 - 2.7 | >= 5.3.0 |
Installation
@ -24,20 +24,30 @@ Installation
### Step 1: Download the GregwarCaptchaBundle
Use composer require to download and install the package.
At the end of the installation you can automaticly create the configuration thanks to the Symfony recipe.
At the end of the installation, the bundle is automatically registered thanks to the Symfony recipe.
``` bash
composer require gregwar/captcha-bundle
```
If you don't use flex, register it manually:
```php
<?php
// config/bundles.php
return [
// ...
Gregwar\CaptchaBundle\GregwarCaptchaBundle::class => ['all' => true]
];
```
Configuration
=============
If you made the configuration automaticly trough the Symfony recipe, you should have the following config file `/config/packages/gregwar_captcha.yaml`
Otherwise you can create it manually `/config/packages/gregwar_captcha.yaml` with the following default configuration:
If you need to customize the global bundle configuration, you can create a `/config/packages/gregwar_captcha.yaml` file with your configuration:
``` yaml
gregwar_captcha: ~
gregwar_captcha:
width: 160
height: 50
```
Usage
@ -91,6 +101,7 @@ number of lines depends on the size of the image). (default=null)
* **background_images**: Sets custom user defined images as the captcha background (1 image is selected randomly). It is recommended to turn off all the effects on the image (ignore_all_effects). The full paths to the images must be passed.
* **interpolation**: enable or disable the interpolation on the captcha
* **ignore_all_effects**: Recommended to use when setting background images, will disable all image effects.
* **session_key**, if you want to host multiple CAPTCHA on the same page, you might have different session keys to ensure proper storage of the clear phrase for those different forms
Example :
@ -121,13 +132,15 @@ The messages are using the translator, you can either change the `invalid_messag
As URL
============
To use a URL to generate a captcha image, you must add the bundle's routing configuration to your app/routing.yml file:
To use a URL to generate a captcha image, you must add the bundle's routing configuration to your `config/routes.yaml` file:
``` yaml
gregwar_captcha_routing:
resource: "@GregwarCaptchaBundle/Resources/config/routing/routing.yml"
```
This will use the bundle's route of "/generate-captcha/{key}" to handle the generation. If this route conflicts with an application route, you can prefix the bundle's routes when you import:
This will use the bundle's route of `/generate-captcha/{key}` to handle the generation. If this route conflicts with an application route, you can prefix the bundle's routes when you import:
``` yaml
gregwar_captcha_routing:
resource: "@GregwarCaptchaBundle/Resources/config/routing/routing.yml"

View File

@ -7,12 +7,17 @@ parameters:
gregwar_captcha.phrase_builder.class: Gregwar\Captcha\PhraseBuilder
services:
Gregwar\CaptchaBundle\Controller\CaptchaController:
public: true
alias: 'gregwar_captcha.controller'
gregwar_captcha.controller:
class: '%gregwar_captcha.controller.class%'
public: true
arguments:
- '@gregwar_captcha.generator'
- '%gregwar_captcha.config%'
autowire: true
# captcha.type:
gregwar_captcha.type:

View File

@ -62,7 +62,8 @@ class CaptchaType extends AbstractType
sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']),
$options['invalid_message'],
$options['bypass_code'],
$options['humanity']
$options['humanity'],
$options['request']
);
$builder->addEventListener(FormEvents::POST_SUBMIT, array($validator, 'validate'));
@ -121,6 +122,7 @@ class CaptchaType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$this->options['mapped'] = false;
$this->options['request'] = null;
$resolver->setDefaults($this->options);
}

View File

@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Captcha validator.
@ -54,13 +55,21 @@ class CaptchaValidator
*/
private $translator;
/**
* Request
*
* @var Request
*/
private $req;
public function __construct(
TranslatorInterface $translator,
SessionInterface $session,
string $key,
string $invalidMessage,
?string $bypassCode,
int $humanity
int $humanity,
?Request $req
) {
$this->translator = $translator;
$this->session = $session;
@ -68,6 +77,7 @@ class CaptchaValidator
$this->invalidMessage = $invalidMessage;
$this->bypassCode = $bypassCode;
$this->humanity = $humanity;
$this->req = $req;
}
public function validate(FormEvent $event): void
@ -94,12 +104,13 @@ class CaptchaValidator
}
}
if (null == $this->req || 1 < $this->req->get('flow_registration_step')) {
$this->session->remove($this->key);
if ($this->session->has($this->key.'_fingerprint')) {
$this->session->remove($this->key.'_fingerprint');
}
}
}
/**
* Retrieve the expected CAPTCHA code.

View File

@ -1,9 +1,9 @@
{
"name": "gregwar/captcha-bundle",
"type": "captcha-bundle",
"name": "cadoles/captcha",
"type": "symfony-bundle",
"description": "Captcha bundle",
"keywords": ["symfony2", "symfony", "captcha", "bot", "visual", "code", "security", "spam"],
"homepage": "https://github.com/Gregwar/CaptchaBundle",
"homepage": "https://github.com/Cadoles/CaptchaBundle",
"license": "MIT",
"authors": [
{
@ -17,9 +17,9 @@
}
],
"require": {
"php": "^7.1.3",
"php": ">=7.1.3",
"ext-gd": "*",
"gregwar/captcha": "~1.1",
"gregwar/captcha": "^1.1.9",
"symfony/form": "~4.0|~5.0",
"symfony/framework-bundle": "~4.0|~5.0",
"symfony/translation": "~4.0|^5.0",