Browse Source

Merge branch 'dev' into 'master'

Default value for url

See merge request dakyaco-public/recaptcha-package!2
master
parent
commit
f929e4aabe
3 changed files with 51 additions and 9 deletions
  1. +48
    -1
      README.md
  2. +2
    -3
      src/Recaptcha.php
  3. +1
    -5
      src/RecaptchaServiceProvider.php

+ 48
- 1
README.md View File

@ -1,3 +1,50 @@
# recaptcha-package
the Public repo of the reCaptcha project.
the Public repo of the reCaptcha project.
## Installation
Require the package:
```sh
$ composer require dakyaco/recaptcha-package
```
Add these lines to ``config/services.php``
```sh
'recaptcha' => [
'secret' => env('RECAPTCHA_SECRET'),
]
```
Now go to ``.env`` file and set your credentials
```sh
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' => 'کپچا صحیح نمی باشد',
]);
}
}
```

+ 2
- 3
src/Recaptcha.php View File

@ -11,7 +11,7 @@ class Recaptcha {
public function __construct() {
$this->secretKey = config('services.recaptcha.secret');
$this->url = config('services.recaptcha.url');
$this->url = 'https://captcha.dakyaco.com/api/v1/validate';
}
@ -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;


+ 1
- 5
src/RecaptchaServiceProvider.php View File

@ -6,11 +6,7 @@ use Illuminate\Support\ServiceProvider;
class RecaptchaServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton('Recaptcha', function () {
$recaptcha = new Recaptcha();
return $recaptcha;
});
$this->app->instance('Recaptcha', new Recaptcha());
}
public function boot() {


Loading…
Cancel
Save