-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
88 lines (59 loc) · 2.12 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
= sfCaptcha plugin =
The `sfCaptchaPlugin` is a symfony plugin that provides captcha functionality based on JpGraph library.
It gives you the lib (incl. jpgraph antispam) and the module to secure your symfony forms in a minute with a good captcha.
== Installation ==
* Install the plugin
{{{
symfony plugin-install http://plugins.symfony-project.com/sfCaptchaPlugin
}}}
* Enable one or more modules in your `settings.yml` (optional)
* sfCaptcha
{{{
all:
.settings:
enabled_modules: [default, sfCaptcha]
}}}
* Put JpGraph core and antispam extension into lib folder or modify in
Captcha.class.php the following line:
* require_once 'jpgraph/jpgraph_antispam.php';
* Clear you cache
{{{
symfony cc
}}}
=== Secure your application ===
To secure a symfony form:
* Optionally add the following routing rules to `routing.yml`
{{{
sf_captcha:
url: /captcha
param: { module: sfCaptcha, action: index }
}}}
* Put the following lines inside of your form
<img src="<?php echo url_for('@sf_captcha'); ?>" />
<?php echo input_tag('captcha'); ?>
* Put the following code into your form's validator yml file:
methods:
post: [ captcha ]
names:
captcha:
required: Yes
required_msg: You should specify Turing number
validators: captchaValidator
captchaValidator:
class: captchaValidator
param:
error: You should specify valid Turing number
* Put the following code into the action which is for the form where captcha
has to be presented:
$g = new Captcha();
$this->getUser()->setAttribute('captcha', $g->generate());
* If you want to customize your captcha phrase please modify the following
method in lib/Captcha.class.php:
public function generate() {
$this->iData = '';
for ($i = 0; $i < 5; ++$i)
$this->iData .= chr(ord('1') + rand(0,8));
return $this->iData;
}
* You're done. Now, if you try to access a secured form, you will be asked to type in captcha.
== TODO ==