canducci/recaptcha

v1.0.1 2016-01-07 12:11 UTC

This package is auto-updated.

Last update: 2024-02-29 02:59:30 UTC


README

CANDUCCI RECAPTCHA

CANDUCCI RECAPTCHA

Build Status Packagist Packagist Packagist Packagist Packagist

Quick start

Required setup

In the require key of composer.json file add the following

"canducci/recaptcha": "1.0.*" 

Run the Composer update comand

$ composer update

In your config/app.php add providers array

'providers' => array(
    ...,    
    Canducci\ReCaptcha\Providers\ReCaptchaServiceProvider::class,
),

At the end of config/app.php add o aliases (Facade) in array

'aliases' => array(
    ...,    
    'ReCaptcha' => Canducci\ReCaptcha\Facades\ReCaptcha::class,
),

Run the Artisan comand

php artisan vendor:publish --force --provider="Canducci\ReCaptcha\Providers\ReCaptchaServiceProvider"

In the config/recaptcha.php add site_key e secret_key of Google ReCaptcha (https://www.google.com/recaptcha/intro/index.html).

###Usage

Blade in View

The @recaptchascript() blade in the tag <head></head>, example:

<!DOCTYPE html>
<html>
    <head>
    <tile>ReCaptcha Test</tile>
    @recaptchascript()
    </head>

The @recaptcha() blade in the tag <form></form>, example:

<form action="/v" method="post">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    @recaptcha()
    <button type="submit">Send</button>
</form>

Variable in View

Controller

public function index1()
{
    return view('index1')
        ->with('script', recaptcha_script())
        ->with('captcha', recaptcha_render());
}

Html

<!DOCTYPE html>
<html>
<head>
    <tile>ReCaptcha Test</tile>
    {!! $script !!}

and

<form action="/v" method="post">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    {!! $captcha !!}
    <button type="submit">Send</button>
</form>

Verify g-recaptcha-response is valid?

Use namespace:

use App\Http\Requests\ReCaptchaRequest;
use Canducci\ReCaptcha\ReCaptcha;
  1. With ReCaptchaRequest, example:
public function post(ReCaptchaRequest $request, ReCaptcha $re)
{
    
}
  1. In the method, example:
public function v(Request $request, ReCaptcha $re)
{    
 
    $valid = $re->valid($request->get('g-recaptcha-response'));
    
    if ( $valid->success() )
    {
        //success
    }
    else
    {
        //not valid
        var_dump( $valid->errors() );
    }
}

###The settings of the tags can be like this:

  1. Function:
$script = recaptcha_script(Canducci\ReCaptcha\ReCaptchaScriptRender::Onload, 
                           Canducci\ReCaptcha\ReCaptchaScriptLanguage::Armenian, 
                           'function_CallBack');
                           
$render = recaptcha_render(Canducci\ReCaptcha\ReCaptchaRenderTheme::Ligth, 
                           Canducci\ReCaptcha\ReCaptchaRenderDataType::Image, 
                           Canducci\ReCaptcha\ReCaptchaRenderDataSize::Normal, 
                           0, 
                           'function_CallBack', 
                           'function_dataExpiredCallBack');
  1. Facade:
use `Canducci\ReCaptcha\Facades\ReCaptcha as ReCaptchaFacade`
$script = ReCaptchaFacade::script(Canducci\ReCaptcha\ReCaptchaScriptRender::Onload, 
                                  Canducci\ReCaptcha\ReCaptchaScriptLanguage::Armenian, 
                                  'function_CallBack');
                                  
$render = ReCaptchaFacade::render(Canducci\ReCaptcha\ReCaptchaRenderTheme::Ligth, 
                                  Canducci\ReCaptcha\ReCaptchaRenderDataType::Image, 
                                  Canducci\ReCaptcha\ReCaptchaRenderDataSize::Normal, 
                                  0, 
                                  'function_CallBack', 
                                  'function_dataExpiredCallBack');
  1. Blade:
@recaptchascript(Canducci\ReCaptcha\ReCaptchaScriptRender::Onload, 
                 Canducci\ReCaptcha\ReCaptchaScriptLanguage::Armenian,
                 'function_CallBack')

@recaptcha(Canducci\ReCaptcha\ReCaptchaRenderTheme::Ligth, 
           Canducci\ReCaptcha\ReCaptchaRenderDataType::Image, 
           Canducci\ReCaptcha\ReCaptchaRenderDataSize::Normal, 
           0, 
           'function_CallBack', 
           'function_dataExpiredCallBack')

Obs: These settings are not compulsory, but if necessary, following Google's website tutorial can be made.