2017 © Pedro Peláez
 

library psr7-recaptcha

image

geggleto/psr7-recaptcha

  • Monday, November 16, 2015
  • by geggleto
  • Repository
  • 2 Watchers
  • 9 Stars
  • 1,421 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 2 Versions
  • 35 % Grown

The README.md

psr7-recaptcha

Configuration

This middleware helps you guard your application with ReCaptcha. You can use it as a middleware or even just as an object in your service layer, (*1)

This package uses the "google/recaptcha" package to handle the bulk of the lifting., (*2)

Usage

The class is invokable, (*3)

$container[Recaptcha::class] = new \ReCaptcha\ReCaptcha($key);

$recaptcha = new \Geggleto\Service\Captcha($container[Recaptcha::class]);

//As Middleware
$app->post('/login', 'Auth:login')->add($recaptcha);

//Anywhere else
$recaptcha->verify($response, $ip);

// Slim 3 Example
// Container File
//...
use Geggleto\Service\Captcha;
use ReCaptcha\ReCaptcha;
//...
    Captcha::class => function ($c) {
        return new Captcha($c[ReCaptcha::class]);
    },
    ReCaptcha::class => function ($c) {
        return new ReCaptcha($c['captcha']['key']);
    },
    'errorHandler' => function ($c) { //CUSTOM Error Handler
        return function (\Slim\Http\Request $request, \Slim\Http\Response $response, $exception) use ($c) {
            return $c['view']->render($response, "errors/servererror.twig", ["exception" => $exception]);
        };
    }    
//...

//In routes.php

//Grab the instance from the Container
$captcha = $app->getContainer()->get(Captcha::class);

//Applying it to routes
$app->post('/signin', Home::class.':processLogin')->add($captcha);
$app->post('/forgot', Home::class.':processForgot')->add($captcha);
$app->post('/recover/{key}', Home::class.':processRecover')->add($captcha);

The Versions

16/11 2015

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware framework slim

16/11 2015

0.0.1

0.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware framework slim