Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1 #164

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

1.1 #164

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getConfigTreeBuilder()
->scalarNode('gc_freq')->defaultValue(100)->end()
->scalarNode('expiration')->defaultValue(60)->end()
->scalarNode('quality')->defaultValue(15)->end()
->scalarNode('invalid_message')->defaultValue('Bad code value')->end()
->end()
;
return $treeBuilder;
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) <2011> Grégoire Passault
Copyright (c) <2012> Grégoire Passault

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Add the following lines to your `deps` file:
[GregwarCaptchaBundle]
git=git://github.com/Gregwar/CaptchaBundle.git
target=/bundles/Gregwar/CaptchaBundle
version=origin/2.0 <- add this if you are using Symfony 2.0
```

Now, run the vendors script to download the bundle:
Expand All @@ -44,8 +45,20 @@ $ git submodule add git://github.com/Gregwar/CaptchaBundle.git vendor/bundles/Gr
$ git submodule update --init
```

***Using Composer***

Add the following to the "require" section of your `composer.json` file:

```
"gregwar/captcha-bundle": "1.0.0"
```

And update your dependencies

### Step 2: Configure the Autoloader

If you use composer, you can skip this step.

Now you will need to add the `Gregwar` namespace to your autoloader:

``` php
Expand Down Expand Up @@ -113,6 +126,7 @@ You can define the following type option :
* **web_path**: absolute path to public web folder (default="%kernel.root_dir%/../web")
* **gc_freq**: frequency of garbage collection in fractions of 1 (default=100)
* **expiration**: maximum lifetime of captcha image files in minutes (default=60)
* **invalid_message**: error message displayed when an non-matching code is submitted (default="Bad code value")

Example :

Expand Down
4 changes: 2 additions & 2 deletions Type/CaptchaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Gregwar\CaptchaBundle\Type;

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session;
use Symfony\Component\DependencyInjection\ContainerInterface;

use Symfony\Component\Form\FormView;
Expand Down Expand Up @@ -45,7 +45,7 @@ public function buildForm(FormBuilder $builder, array $options)
$this->key = $builder->getForm()->getName();

$builder->addValidator(
new CaptchaValidator($this->session, $this->key)
new CaptchaValidator($this->session, $this->key, $options['invalid_message'])
);
}

Expand Down
14 changes: 10 additions & 4 deletions Validator/CaptchaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Gregwar\CaptchaBundle\Validator;

use Symfony\Component\Form\FormValidatorInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormError;

Expand All @@ -24,10 +24,16 @@ class CaptchaValidator implements FormValidatorInterface
*/
private $key;

public function __construct(Session $session, $key)
/**
* Error message text for non-matching submissions
*/
private $invalidMessage;

public function __construct(Session $session, $key, $invalidMessage)
{
$this->session = $session;
$this->key = $key;
$this->invalidMessage = $invalidMessage;
}

public function validate(FormInterface $form)
Expand All @@ -37,7 +43,7 @@ public function validate(FormInterface $form)

if (!($code && $excepted_code && is_string($code) && is_string($excepted_code)
&& $this->niceize($code) == $this->niceize($excepted_code))) {
$form->addError(new FormError('Bad code value'));
$form->addError(new FormError($this->invalidMessage));
}

$this->session->remove($this->key);
Expand All @@ -61,7 +67,7 @@ private function getExceptedCode()
/**
* Process the codes
*/
private function niceize($code)
private function niceize($code)
{
return strtr(strtolower($code), 'oil', '01l');
}
Expand Down
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "gregwar/captcha-bundle",
"type": "captcha-bundle",
"description": "Captcha bundle",
"keywords": ["symfony2", "captcha", "bot", "visual", "code", "security", "spam"],
"homepage": "https://github.com/Gregwar/ImageBundle",
"license": "MIT",
"authors": [
{
"name": "Grégoire Passault",
"email": "[email protected]",
"homepage": "http://www.gregwar.com/"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Gregwar\\CaptchaBundle": ""
}
},
"target-dir": "Gregwar/CaptchaBundle"
}