1 | <?php |
||
27 | class CaptchaValidator extends Validator |
||
28 | { |
||
29 | /** |
||
30 | * @var bool whether to skip this validator if the input is empty. |
||
31 | */ |
||
32 | public $skipOnEmpty = false; |
||
33 | /** |
||
34 | * @var bool whether the comparison is case sensitive. Defaults to false. |
||
35 | */ |
||
36 | public $caseSensitive = false; |
||
37 | /** |
||
38 | * @var string the route of the controller action that renders the CAPTCHA image. |
||
39 | */ |
||
40 | public $captchaAction = 'site/captcha'; |
||
41 | |||
42 | |||
43 | /** |
||
44 | * @inheritdoc |
||
45 | */ |
||
46 | 2 | public function init() |
|
47 | { |
||
48 | 2 | parent::init(); |
|
49 | 2 | if ($this->message === null) { |
|
50 | 2 | $this->message = Yii::t('yii', 'The verification code is incorrect.'); |
|
51 | } |
||
52 | 2 | } |
|
53 | |||
54 | /** |
||
55 | * @inheritdoc |
||
56 | */ |
||
57 | protected function validateValue($value) |
||
64 | |||
65 | /** |
||
66 | * Creates the CAPTCHA action object from the route specified by [[captchaAction]]. |
||
67 | * @return \yii\captcha\CaptchaAction the action object |
||
68 | * @throws InvalidConfigException |
||
69 | */ |
||
70 | public function createCaptchaAction() |
||
71 | { |
||
72 | $ca = Yii::$app->createController($this->captchaAction); |
||
73 | if ($ca !== false) { |
||
74 | /* @var $controller \yii\base\Controller */ |
||
75 | list($controller, $actionID) = $ca; |
||
76 | $action = $controller->createAction($actionID); |
||
77 | if ($action !== null) { |
||
78 | return $action; |
||
79 | } |
||
80 | } |
||
81 | throw new InvalidConfigException('Invalid CAPTCHA action ID: ' . $this->captchaAction); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @inheritdoc |
||
86 | */ |
||
87 | public function clientValidateAttribute($model, $attribute, $view) |
||
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | public function getClientOptions($model, $attribute) |
||
117 | } |
||
118 |