Skip to content

Commit 890406f

Browse files
Invisible
1 parent 8228f58 commit 890406f

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
"extra": {
2626
"branch-alias": {
2727
"dev-master": "2.2-dev"
28+
},
29+
"laravel": {
30+
"providers": [
31+
"Greggilbert\\Recaptcha\\RecaptchaServiceProvider"
32+
],
33+
"aliases": {
34+
"Recaptcha": "Greggilbert\\Recaptcha\\Facades\\Recaptcha"
35+
}
2836
}
2937
},
3038
"minimum-stability": "dev"

src/Facades/Recaptcha.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ protected static function getFacadeAccessor()
1111
{
1212
return 'recaptcha';
1313
}
14-
}
14+
}

src/Recaptcha.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Recaptcha
99

1010
protected $config = [ ];
1111

12-
protected $dataParameterKeys = [ 'theme', 'type', 'callback', 'tabindex', 'expired-callback' ];
12+
protected $dataParameterKeys = [ 'theme', 'type', 'callback', 'tabindex', 'expired-callback', 'badge' ];
1313

1414

1515
public function __construct($service, $config)

src/RecaptchaServiceProvider.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ public function register()
5757
protected function bindRecaptcha()
5858
{
5959
$this->app->bind('recaptcha.service', function () {
60-
if (app('config')->get('recaptcha.version', false) === 2 || app('config')->get('recaptcha.v2', false)) {
60+
if (
61+
app('config')->get('recaptcha.version') === 'invisible'
62+
) {
63+
return new Service\CheckRecaptchaInvisible;
64+
}
65+
66+
if (
67+
app('config')->get('recaptcha.version') === 2
68+
|| app('config')->get('recaptcha.v2')
69+
) {
6170
return new Service\CheckRecaptchaV2;
6271
}
6372

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Greggilbert\Recaptcha\Service;
4+
5+
/**
6+
* Handle sending out and receiving a response to validate the captcha
7+
*/
8+
class CheckRecaptchaInvisible extends CheckRecaptchaV2
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*/
13+
public function getTemplate()
14+
{
15+
return 'captchainvisible';
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
if ( ! function_exists('renderDataAttributes')) {
3+
function renderDataAttributes($attributes)
4+
{
5+
$mapped = [ ];
6+
foreach ($attributes as $key => $value) {
7+
$mapped[] = 'data-' . $key . '="' . $value . '"';
8+
};
9+
10+
return implode(' ', $mapped);
11+
}
12+
}
13+
?>
14+
<script src='https://www.google.com/recaptcha/api.js?render=onload{{ (isset($lang) ? '&hl='.$lang : '') }}'></script>
15+
<div
16+
class="g-recaptcha"
17+
data-sitekey="{{ $public_key }}"
18+
data-size="invisible"
19+
<?= renderDataAttributes($dataParams) ?>
20+
></div>

0 commit comments

Comments
 (0)