Skip to content

Commit cb617ba

Browse files
committed
version 1.0
1 parent bcbc787 commit cb617ba

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

CaptchaAction.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
class CaptchaAction extends \yii\captcha\CaptchaAction
66
{
7-
public $minLength = 4;
8-
public $maxLength = 9;
9-
public $fontFile = '@yii/captcha/SpicyRice.ttf';
7+
public $fontFile = '@developit/captcha/font/LithosPro-Regular.otf';
108
public $foreColor = 0x999999;
9+
public $type = 'default'; // numbers & letters
1110

1211
protected function generateVerifyCode()
1312
{
@@ -21,10 +20,21 @@ protected function generateVerifyCode()
2120
$this->maxLength = 9;
2221
}
2322
$length = mt_rand($this->minLength, $this->maxLength);
24-
$numbers = '0123456789';
23+
24+
$str = '0123456789bcdfghjklmnpqrstvwxyz';
2525
$code = '';
2626
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+
}
2838
}
2939

3040
return $code;

README.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
yii2 captcha
22
============
3-
yii2 numeric captcha
3+
4+
![screenshot](http://www.developit.ir/tmp/yii2-captcha.jpg)
45

56
Installation
67
------------
@@ -10,13 +11,13 @@ The preferred way to install this extension is through [composer](http://getcomp
1011
Either run
1112

1213
```
13-
php composer.phar require --prefer-dist developit/yii2-captcha "dev-master"
14+
php composer.phar require --prefer-dist developit/yii2-captcha "~1.0"
1415
```
1516

1617
or add
1718

1819
```
19-
"developit/yii2-captcha": "dev-master"
20+
"developit/yii2-captcha": "~1.0"
2021
```
2122

2223
to the require section of your `composer.json` file.
@@ -25,7 +26,29 @@ to the require section of your `composer.json` file.
2526
Usage
2627
-----
2728

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()`:
2930

3031
```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+

font/LithosPro-Regular.otf

78.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)