承接 giginc/cakephp3-recaptcha 相关项目开发

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

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

giginc/cakephp3-recaptcha

最新稳定版本:0.0.5

Composer 安装命令:

composer require giginc/cakephp3-recaptcha

包简介

Recaptcha for CakePHP 3

README 文档

README

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require giginc/cakephp3-recaptcha

followed by the command:

composer update

Load plugin

From command line:

bin/cake plugin load Recaptcha

Load Component and Configure

Override default configure from loadComponent:

Recaptcha version2
$this->loadComponent('Recaptcha.Recaptcha', [
    'enable' => true,     // true/false
    'version' => 2,
    'sitekey' => 'your_site_key', //if you don't have, get one: https://www.google.com/recaptcha/intro/index.html
    'secret' => 'your_secret',
    'type' => 'image',  // image/audio
    'theme' => 'light', // light/dark
    'lang' => 'vi',      // default en
    'size' => 'normal'  // normal/compact
]);

Recaptcha version3
$this->loadComponent('Recaptcha.Recaptcha', [
    'enable' => true,     // true/false
    'version' => 3,
    'sitekey' => 'your_site_key', //if you don't have, get one: https://www.google.com/recaptcha/intro/index.html
    'secret' => 'your_secret',
    'scoreThreshold' => 0.5, // score threshold (default 0.5)
]);

Override default configure from app config file:

file: config/app.php
Recaptcha version2
    /**
     * Recaptcha configuration.
     *
     */
    'Recaptcha' => [
        'enable' => true,
        'version' => 2,
        'sitekey' => 'your_site_key',
        'secret' => 'your_secret',
        'type' => 'image',
        'theme' => 'light',
        'lang' => 'es',
        'size' => 'normal'
    ]

Recaptcha version3
    /**
     * Recaptcha configuration.
     *
     */
    'Recaptcha' => [
        'enable' => true,
        'version' => 3,
        'sitekey' => 'your_site_key',
        'secret' => 'your_secret',
    ]

Override default configure from recaptcha config file:

file: config/recaptcha.php
<?php
return [
    /**
     * Recaptcha configuration.
     *
     */
    'Recaptcha' => [
        'enable' => true,
        'version' => 3,
        'sitekey' => 'your_site_key',
        'secret' => 'your_secret',
    ]
];

Load recaptcha config file:

file: config/bootstrap.php
    Configure::load('recaptcha', 'default', true);

Config preference:

  1. loadComponent config options
  2. recaptcha config file
  3. app config file

Usage

Display recaptcha in your view:

    <?= $this->Form->create() ?>
    <?= $this->Form->control('email') ?>
    <?= $this->Recaptcha->display() ?>  // Display recaptcha box in your view, if configure has enable = false, nothing will be displayed
    <?= $this->Form->button() ?>
    <?= $this->Form->end() ?>

Verify in your controller function

    public function forgotPassword()
    {
        if ($this->request->is('post')) {
            if ($this->Recaptcha->verify()) { // if configure enable = false, it will always return true
                //do something here
            }
            $this->Flash->error(__('Please pass Google Recaptcha first'));
        }
    }

LICENSE

The MIT License (MIT) Copyright (c) 2013

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

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