geggleto / psr7-recaptcha
0.0.1
2015-11-16 15:35 UTC
Requires
- google/recaptcha: ~1.1
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.0
- slim/slim: ^3.0-RC2
This package is auto-updated.
Last update: 2024-08-29 03:29:41 UTC
README
配置
此中间件可以帮助您使用 ReCaptcha 保护您的应用程序。您可以使用它作为中间件,也可以在服务层中仅作为对象使用
此包使用 "google/recaptcha" 包来处理大部分工作。
用法
该类可调用
$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);