dev-master
9999999-devGoogle Invisible reCaptcha for Yii2
MIT
The Requires
by aivanouski
yii2 recaptcha
dev-develop
dev-developGoogle Invisible reCaptcha for Yii2
MIT
The Requires
by szaboolcs
yii2 recaptcha
Google Invisible reCaptcha for Yii2
Based on reCaptcha API 2.0., (*1)
The preferred way to install this extension is through composer., (*2)
php composer.phar require --prefer-dist "aivanouski/yii2-invisible-recaptcha" "*"
, (*3)
or add, (*4)
"aivanouski/yii2-invisible-recaptcha" : "*"
, (*5)
to the require section of your application's composer.json file., (*6)
'components' => [ 'captcha' => [ 'name' => 'captcha', 'class' => 'szaboolcs\InvisibleRecaptcha', 'siteKey' => 'your siteKey', 'secret' => 'your secret' ] ]
login.php, (*7)
<?php use szaboolcs\recaptcha\InvisibleRecaptcha; use yii\widgets\ActiveForm; $form = ActiveForm::begin([ 'id' => 'login-form' ]); echo $form->field($model, 'username'); echo $form->field($model, 'password'); echo InvisibleRecaptcha::widget([ 'name' => 'Submit', 'formSelector' => '#login-form' ]); ActiveForm::end();
LoginController.php, (*8)
<?php namespace app\controllers; use szaboolcs\recaptcha\InvisibleRecaptchaValidator; use app\models\Login; use Yii; class LoginController { public function actionLoginForm() { $model = new Login(); return $this->render('login', [ 'model' => $model ]); } public function actionLogin() { $model = new Login(); $model->load(Yii::$app->request->post()); if ($model->validate() && InvisibleRecaptchaValidator::validate(Yii::$app->request->post(InvisibleRecaptchaValidatior::POST_ELEMENT)) && Yii::$app->user->login($model->getUser())) { return $this->goHome(); } return $this->render('login', [ 'model' => $model ]); } }
Login.php, (*9)
<?php use yii\base\Model; use app\models\User; class Login extends Model { public $username; public $password; private $_user; public function rules() { // ... } public function getUser() { if (!$this->_user) { $this->_user = User::find()->byUsername($this->username)->one(); } return $this->_user; } }
Google Invisible reCaptcha for Yii2
MIT
yii2 recaptcha
Google Invisible reCaptcha for Yii2
MIT
yii2 recaptcha