File tree 3 files changed +43
-10
lines changed
3 files changed +43
-10
lines changed Original file line number Diff line number Diff line change 4
4
5
5
class CaptchaAction extends \yii \captcha \CaptchaAction
6
6
{
7
- public $ minLength = 4 ;
8
- public $ maxLength = 9 ;
9
- public $ fontFile = '@yii/captcha/SpicyRice.ttf ' ;
7
+ public $ fontFile = '@developit/captcha/font/LithosPro-Regular.otf ' ;
10
8
public $ foreColor = 0x999999 ;
9
+ public $ type = 'default ' ; // numbers & letters
11
10
12
11
protected function generateVerifyCode ()
13
12
{
@@ -21,10 +20,21 @@ protected function generateVerifyCode()
21
20
$ this ->maxLength = 9 ;
22
21
}
23
22
$ length = mt_rand ($ this ->minLength , $ this ->maxLength );
24
- $ numbers = '0123456789 ' ;
23
+
24
+ $ str = '0123456789bcdfghjklmnpqrstvwxyz ' ;
25
25
$ code = '' ;
26
26
for ($ i = 0 ; $ i < $ length ; $ i ++) {
27
- $ code .= $ numbers [mt_rand (0 , 9 )];
27
+ switch ($ this ->type )
28
+ {
29
+ case 'numbers ' :
30
+ $ code .= $ str [mt_rand (0 , 9 )];
31
+ break ;
32
+ case 'letters ' :
33
+ $ code .= $ str [mt_rand (10 , 30 )];
34
+ break ;
35
+ default :
36
+ $ code .= $ str [mt_rand (0 , 30 )];
37
+ }
28
38
}
29
39
30
40
return $ code ;
Original file line number Diff line number Diff line change 1
1
yii2 captcha
2
2
============
3
- yii2 numeric captcha
3
+
4
+ ![ screenshot] ( http://www.developit.ir/tmp/yii2-captcha.jpg )
4
5
5
6
Installation
6
7
------------
@@ -10,13 +11,13 @@ The preferred way to install this extension is through [composer](http://getcomp
10
11
Either run
11
12
12
13
```
13
- php composer.phar require --prefer-dist developit/yii2-captcha "dev-master "
14
+ php composer.phar require --prefer-dist developit/yii2-captcha "~1.0 "
14
15
```
15
16
16
17
or add
17
18
18
19
```
19
- "developit/yii2-captcha": "dev-master "
20
+ "developit/yii2-captcha": "~1.0 "
20
21
```
21
22
22
23
to the require section of your ` composer.json ` file.
@@ -25,7 +26,29 @@ to the require section of your `composer.json` file.
25
26
Usage
26
27
-----
27
28
28
- Once the extension is installed, simply use it in your code by :
29
+ Once the extension is installed, simply modify your controler, add or change methode ` actions() ` :
29
30
30
31
``` php
31
- <?= \developit\captcha\CaptchaAction; ?>```
32
+ public function actions()
33
+ {
34
+ $this->layout = $this->setting['layout'];
35
+ return [
36
+ 'error' => [
37
+ 'class' => 'yii\web\ErrorAction',
38
+ ],
39
+ 'captcha' => [
40
+ 'class' => 'developit\captcha\CaptchaAction',
41
+ 'type' => 'numbers', // 'numbers', 'letters' or 'default' (contains numbers & letters)
42
+ 'minLength' => 4,
43
+ 'maxLength' => 4,
44
+ ],
45
+ ];
46
+ }
47
+ ```
48
+
49
+ In view
50
+ ``` php
51
+ <?=
52
+ $form->field($model, 'verifyCode')->widget(Captcha::className())
53
+ ?>
54
+
You can’t perform that action at this time.
0 commit comments