From 551ffb41b5d0770de65855fe07cb4df543916991 Mon Sep 17 00:00:00 2001 From: Amir Reza Mehrbakhsh Date: Mon, 2 Sep 2019 10:29:35 +0430 Subject: [PATCH] Update README.md --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++- src/Recaptcha.php | 3 +-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1b37589..bd6d559 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,52 @@ # recaptcha-package -the Public repo of the reCaptcha project. \ No newline at end of file +the Public repo of the reCaptcha project. + +## Installation +Require the package: + +```sh +$ composer require dakyaco/ketabuzz +``` + +Add these lines to ``config/services.php`` + +```sh +'recaptcha' => [ + 'url' => env('RECAPTCHA_URL'), + 'secret' => env('RECAPTCHA_SECRET'), +] +``` + +Now go to ``.env`` file and set your credentials + +```sh +RECAPTCHA_URL= +RECAPTCHA_SECRET=your-secret-key +``` +## How to use +Go to ``app/Http/Controllers/LoginController.php`` and add following code + +(you can handle it whatever you want. It's just an option) + +```sh +use Dakyaco\Recaptcha\Facade\Recaptcha; + +use AuthenticatesUsers { + validateLogin as validateCredentials; +} + +// .... + +protected function validateLogin(Request $request) +{ + $result = Recaptcha::verify($request); + if($result['valid']) { + $this->validateCredentials($request); + } else { + throw ValidationException::withMessages([ + 'recaptcha' => 'کپچا صحیح نمی باشد', + ]); + } +} +``` \ No newline at end of file diff --git a/src/Recaptcha.php b/src/Recaptcha.php index 03b04b9..bdd76db 100644 --- a/src/Recaptcha.php +++ b/src/Recaptcha.php @@ -24,8 +24,7 @@ class Recaptcha { 'p-captcha-session' => $session, 'sitekey' => $this->secretKey ]; - // TODO: document this: - // add keys to config/services.php + $result = $this->call('POST', $this->url, $data); $result = json_decode($result, true); return $result;