2017 © Pedro Peláez
 

library charcoal-recaptcha

Google reCAPTCHA for Charcoal.

image

mcaskill/charcoal-recaptcha

Google reCAPTCHA for Charcoal.

  • Wednesday, May 23, 2018
  • by mcaskill
  • Repository
  • 1 Watchers
  • 0 Stars
  • 826 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 6 % Grown

The README.md

Google reCAPTCHA for Charcoal

![License][badge-license] Latest Stable Version ![Code Quality][badge-scrutinizer] Coverage Status ![Build Status][badge-travis], (*1)

Google reCAPTCHA for Charcoal, (*2)

A Charcoal service provider for the Google reCAPTCHA client Library., (*3)

This package can be used as a PSR-7 middleware or as an object in your service layer., (*4)

Installation

composer require mcaskill/charcoal-recaptcha

See composer.json for depenencides., (*5)

What's inside?

  • Charcoal\ReCaptcha\CaptchaServiceProvider: Service provider.
  • Charcoal\ReCaptcha\CaptchaConfig: Configuring the CAPTCHA service.
  • Charcoal\ReCaptcha\CaptchaAwareTrait: Convenient trait for interfacing with the CAPTCHA service.
  • Charcoal\ReCaptcha\Captcha: Service that handles the reCAPTCHA client.
  • Charcoal\ReCaptcha\LocalizedCaptcha: Translator-aware variant of the service.

Usage

use Charcoal\ReCaptcha\Captcha;

$captcha = new Captcha([
    'config' => [
        'public_key'  => '…',
        'private_key' => '…',
    ]
]);

// As middleware
$app->post('/signup', '…')->add($captcha);

// As standalone, with direct user input
$captcha->verify($input, $ip);

// With a PSR-7 request
$captcha->verifyRequest($request);

// Display the widget in your views
echo $captcha->display(
    [
        'data-theme' => 'dark',
        'data-type' =>  'audio',
    ],
    [
        'hl' => 'fr'
    ]
);

By default, the Captcha adapter will defer the instantiation of ReCaptcha until the first verification request., (*6)

Custom ReCaptcha Class

The ReCaptcha class be swapped using the client_class option., (*7)

use Charcoal\ReCaptcha\Captcha;
use MyApp\ MyCustomReCaptcha;

$captcha = new Captcha([
    'config' => [
        'public_key'  => '…',
        'private_key' => '…',
    ],
    'client_class' =>  MyCustomReCaptcha::class
]);

Custom ReCaptcha Instance

An instance of the ReCaptcha class can be assigned using the client option., (*8)

use Charcoal\ReCaptcha\Captcha;
use ReCaptcha\ReCaptcha;
use ReCaptcha\RequestMethod\CurlPost;

$client = new ReCaptcha('…', new CurlPost());

$captcha = new Captcha([
    'config' => [
        'public_key'  => '…',
        'private_key' => '…',
    ],
    'client' => $client
]);

Service Provider

If CaptchaServiceProvider is used, the following are provided., (*9)

Parameters

Services

  • charcoal/captcha: An instance of Captcha.

Registering

Via Charcoal configuration file:, (*10)

{
    "apis": {
        "google": {
            "recaptcha": {
                "public_key": "…",
                "private_key": "…"
            }
        },
    },
    "service_providers": {
        "charcoal/re-captcha/captcha": {}
    }
}

Via PHP:, (*11)

$container->register(new Charcoal\ReCaptcha\CaptchaServiceProvider(), [
    'charcoal/captcha/config' => [
        'public_key'  => '…',
        'private_key' => '…'
    ]
]);

Acknowledgements

This package is inspired by:, (*12)

License

  • Charcoal reCAPTCHA component is licensed under the MIT license. See LICENSE for details.
  • Charcoal framework is licensed under the MIT license. See LICENSE for details.
  • Google reCAPTCHA PHP client library is licensed under the BSD License. See the LICENSE file for details.

The Versions

02/02 2018
02/02 2018
07/03 2017
07/03 2017
02/03 2017

0.1

0.1.0.0

Google reCAPTCHA for Charcoal.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/03 2017

v0.1.0

0.1.0.0

Google reCAPTCHA for Charcoal.

  Sources   Download

MIT

The Requires

 

The Development Requires