承接 wearesho-team/yii2-recaptcha-v3 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wearesho-team/yii2-recaptcha-v3

最新稳定版本:1.1.0

Composer 安装命令:

composer require wearesho-team/yii2-recaptcha-v3

包简介

reCAPTCHA v3 Yii2 Integration

README 文档

README

Build Status codecov

This module provides behavior, validator and bootstrap to connection reCAPTCHA to Yii2 Application.

Installation

composer require wearesho-team/yii2-recaptcha-v3:^1.1

Usage

Configuration

To configure current reCAPTCHA environment (will be used in Behavior) you have to use ConfigInterface.

Environment Configuration

Key Required Format Description
RECAPTCHA_ENVIRONMENT - string YII_ENV will be used default

Bootstrap

<?php

use Wearesho\ReCaptcha;

// config.php

return [
    'bootstrap' => [
        'reCaptcha' => [
            'class' => ReCaptcha\V3\Yii2\Bootstrap::class,
            'config' => ReCaptcha\V3\EnvironmentConfig::class, // or another config interface implementation
            'yiiConfig' => ReCaptcha\V3\Yii2\EnvironmentConfig::class, // will be used for environment checking
        ],
        // another bootstraps      
    ],
];

See wearesho-team/recaptcha-v3 docs for environment config details.

Validator

<?php

use yii\base;
use Wearesho\ReCaptcha;

class Model extends base\Model {
    /** @var string token for reCAPTCHA verification */
    public $token;
    
    public function rules(): array
    {
        return [
            [['token',], 'required',],
            [['token',], ReCaptcha\V3\Yii2\Validator::class,
                'min' => 0.5,
                'max' => 1,
                'actions' => ['login',],
                'hostNames' => ['wearesho.com',],
            ],
        ];
    }
}

See Validator source code for properties details.

Behavior

Behavior is way to validate reCAPTCHA token in web\Controller.

<?php

use yii\web;
use Wearesho\ReCaptcha;

class Controller extends web\Controller 
{
    public function behaviors(): array
    {
        return [
            'reCaptcha' => [
                'class' => ReCaptcha\V3\Yii2\Behavior::class,
                'actions' => [
                    'login' => ['post',],   
                ],
                'min' => 0.5,
                'max' => 1,
                'hostNames' => ['wearesho.com',],
                'environments' => ['prod',],
            ],      
        ];
    }
    
    // controller code
}

If environments property specified, environment check will be performed before others. See configuration section for environment configuring details.

In this example behavior will check for X-ReCaptcha-Token header before login action (only in case of POST action). If header is missing or it's value invalid \yii\web\BadRequestHttpException will be threw. See Behavior source code for code details and property docs.

When checking reCAPTCHA response action attribute will be used current controller ID, action ID and request method: controlleractionmethod, without dividers. Example: loginindexpost, where login is controller ID, index is action ID and post is request method).

Note: Behavior::actions property works different way compared to Validator

Contributors

License

MIT

统计信息

  • 总下载量: 180
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固