Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDaDeng committed Jan 8, 2019
1 parent ae32164 commit f4172fd
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 31 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Include Template script in your bottom/header of your page, e.g.
##### Example Usage

``` html
{{--if laravel version <=5.6, please use {{ csrf_field() }}--}}
<form method="POST" action="/verify">
@csrf
<div id="form_1_id"></div>
Expand Down Expand Up @@ -289,6 +290,8 @@ Route::post('/verify', 'ReCaptchaController@verify');

4. Create your form in index.blade.php:
``` html
{{--if laravel version <=5.6, please use {{ csrf_field() }}--}}

<form method="POST" action="/verify">
@csrf
<div id="contact_us_id"></div>
Expand Down
103 changes: 72 additions & 31 deletions src/Providers/GoogleReCaptchaV2ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,48 @@ class GoogleReCaptchaV2ServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'GoogleReCaptchaV2');
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'GoogleReCaptchaV2');

if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
}

public function bindConfig()
{
$this->app->bind(
ReCaptchaConfigV2Interface::class,
ReCaptchaConfigV2::class
);
}

/**
* @param $method
*/
public function bindRequest($method)
{
switch ($method) {
case 'guzzle':
$this->app->bind(
RequestClientInterface::class,
GuzzleRequestClient::class
);
break;
case'curl':
$this->app->bind(
RequestClientInterface::class,
CurlRequestClient::class
);
break;
default:
$this->app->bind(
RequestClientInterface::class,
CurlRequestClient::class
);
break;
}
}

/**
* Register services.
*
Expand All @@ -38,39 +73,45 @@ public function boot()
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../../config/googlerecaptchav2.php', 'googlerecaptchav2'
__DIR__ . '/../../config/googlerecaptchav2.php', 'googlerecaptchav2'
);

if (! $this->app->has(ReCaptchaConfigV2Interface::class)) {
$this->app->bind(
ReCaptchaConfigV2Interface::class,
ReCaptchaConfigV2::class
);
}
$laravel = app();
$version = $laravel::VERSION;

// default strategy
if (! $this->app->has(RequestClientInterface::class)) {
switch ($this->app->get(ReCaptchaConfigV2Interface::class)->getRequestMethod()) {
case 'guzzle':
$this->app->bind(
RequestClientInterface::class,
GuzzleRequestClient::class
);
break;
case'curl':
$this->app->bind(
RequestClientInterface::class,
CurlRequestClient::class
);
break;
default:
$this->app->bind(
RequestClientInterface::class,
CurlRequestClient::class
);
break;
if (version_compare($version, '5.7.*') === 1 || version_compare($version, '5.6.*') === 1 || version_compare($version, '5.5.*') === 1) {

if (!$this->app->has(ReCaptchaConfigV2Interface::class)) {
$this->bindConfig();
}
// default strategy
if (!$this->app->has(RequestClientInterface::class)) {
switch ($this->app->get(ReCaptchaConfigV2Interface::class)->getRequestMethod()) {
case 'guzzle':
$this->app->bind(
RequestClientInterface::class,
GuzzleRequestClient::class
);
break;
case'curl':
$this->app->bind(
RequestClientInterface::class,
CurlRequestClient::class
);
break;
default:
$this->app->bind(
RequestClientInterface::class,
CurlRequestClient::class
);
break;
}
}
} else {
$this->bindConfig();
$this->bindRequest(app(ReCaptchaConfigV2Interface::class)->getRequestMethod());
}

$this->app->bind('GoogleReCaptchaV2', function () {
$service = new GoogleReCaptchaV2Service(app(ReCaptchaConfigV2Interface::class), app(RequestClientInterface::class));

Expand All @@ -87,12 +128,12 @@ protected function bootForConsole()
{
// Publishing the configuration file.
$this->publishes([
__DIR__.'/../../config/googlerecaptchav2.php' => config_path('googlerecaptchav2.php'),
__DIR__ . '/../../config/googlerecaptchav2.php' => config_path('googlerecaptchav2.php'),
], 'googlerecaptchav2.config');

// Publishing the views.
$this->publishes([
__DIR__.'/../../resources/views' => base_path('resources/views'),
__DIR__ . '/../../resources/views' => base_path('resources/views'),
], 'googlerecaptchav2.views');
}

Expand Down

0 comments on commit f4172fd

Please sign in to comment.