Instalação

Você pode instalar este plugin em seu aplicativo CakePHP usando composer .

A maneira recomendada de instalar pacotes do composer é:

composer require crabstudio/recaptcha

seguido do comando:

composer update

Carregar plug-in

Da linha de comando:

bin/cake plugin load Recaptcha

Carregar componente e configurar

Substitua a configuração padrão de loadComponent:

$this->loadComponent('Recaptcha.Recaptcha', [
    'enable' => true,     // true/false
    '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
]);

Substitua a configuração padrão do arquivo de configuração do aplicativo:

file: config/app.php

    /**
     * Recaptcha configuration.
     *
     */
    'Recaptcha' => [
        'enable' => true,
        'sitekey' => 'your_site_key',
        'secret' => 'your_secret',
        'type' => 'image',
        'theme' => 'light',
        'lang' => 'es',
        'size' => 'normal'
    ]

Substitua a configuração padrão do arquivo de configuração recaptcha:

file: config/recaptcha.php

<?php

return [
    /**
     * Recaptcha configuration.
     *
     */
    'Recaptcha' => [
        'enable' => true,
        'sitekey' => 'your_site_key',
        'secret' => 'your_secret',
        'type' => 'image',
        'theme' => 'light',
        'lang' => 'es',
        'size' => 'normal'
    ]
];

Carregar arquivo de configuração do recaptcha:

file: config/bootstrap.php

    Configure::load('recaptcha', 'default', true);

Preferência de configuração:

  1. Opções de configuração do loadComponent
  2. arquivo de configuração recaptcha
  3. arquivo de configuração do aplicativo

Uso

Exiba o recaptcha em sua visualização:

    <?= $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() ?>
 

Verifique na função do seu controlador

    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'));
        }
    }

Link para a fonte:
Recaptcha

0 Comments

Say something

Login OR Register to write comments

Quer receber atualizações?

Confirme seu email e receba as atualizações mais recentes