Skip to content

Commit 1b67a18

Browse files
authored
Merge pull request #19 from DutchCodingCompany/development
development to main
2 parents ad0147b + f0b32ce commit 1b67a18

12 files changed

Lines changed: 154 additions & 32 deletions

.github/workflows/dependabot-auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v2.2.0
16+
uses: dependabot/fetch-metadata@v3.0.0
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

.github/workflows/php-cs-fixer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
steps:
1010
- name: Checkout code
11-
uses: actions/checkout@v4
11+
uses: actions/checkout@v6
1212
with:
1313
ref: ${{ github.head_ref }}
1414

@@ -18,6 +18,6 @@ jobs:
1818
args: --config=.php-cs-fixer.php --allow-risky=yes
1919

2020
- name: Commit changes
21-
uses: stefanzweifel/git-auto-commit-action@v5
21+
uses: stefanzweifel/git-auto-commit-action@v7
2222
with:
2323
commit_message: Fix styling

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
steps:
2626
- name: Checkout code
27-
uses: actions/checkout@v4
27+
uses: actions/checkout@v6
2828

2929
- name: Setup PHP
3030
uses: shivammathur/setup-php@v2

.github/workflows/run-tests.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,30 @@ on:
1212

1313
jobs:
1414
test:
15-
runs-on: ${{ matrix.os }}
15+
runs-on: ubuntu-latest
1616
timeout-minutes: 5
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: [ubuntu-latest]
21-
php: [8.3, 8.2]
22-
laravel: [11.*]
23-
stability: [prefer-stable]
24-
testbench: [9.*]
25-
26-
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.os }}
20+
php: ['8.2', '8.3', '8.4', '8.5']
21+
laravel: ['11.*', '12.*', '13.*']
22+
livewire: ['3.*', '4.*']
23+
exclude:
24+
- laravel: '13.*'
25+
php: '8.2'
26+
include:
27+
- laravel: '11.*'
28+
testbench: '9.*'
29+
- laravel: '12.*'
30+
testbench: '10.*'
31+
- laravel: '13.*'
32+
testbench: '11.*'
33+
34+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Livewire ${{ matrix.livewire }}
2735

2836
steps:
2937
- name: Checkout code
30-
uses: actions/checkout@v4
38+
uses: actions/checkout@v6
3139

3240
- name: Setup PHP
3341
uses: shivammathur/setup-php@v2
@@ -43,8 +51,8 @@ jobs:
4351
4452
- name: Install dependencies
4553
run: |
46-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
47-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
54+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "livewire/livewire:${{ matrix.livewire }}" --no-interaction --no-update
55+
composer update --prefer-stable --prefer-dist --no-interaction
4856
4957
- name: List Installed Dependencies
5058
run: composer show -D

.github/workflows/update-changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@v4
13+
uses: actions/checkout@v6
1414
with:
1515
ref: main
1616

@@ -21,7 +21,7 @@ jobs:
2121
release-notes: ${{ github.event.release.body }}
2222

2323
- name: Commit updated CHANGELOG
24-
uses: stefanzweifel/git-auto-commit-action@v5
24+
uses: stefanzweifel/git-auto-commit-action@v7
2525
with:
2626
branch: main
2727
commit_message: Update CHANGELOG

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ version you are going to implement.
2222

2323
This package supports the following versions. Note that each version requires a different sitekey/secretkey pair:
2424

25-
| **Version** | **Docs** | **Notes** |
26-
|----------------------|-------------------------------------------------------------------|-----------------------------|
27-
| **v3** (recommended) | [V3 Docs](https://developers.google.com/recaptcha/docs/v3) | |
28-
| **v2** | [V2 Docs](https://developers.google.com/recaptcha/docs/display) | |
29-
| **v2 invisible** | [V2 Docs](https://developers.google.com/recaptcha/docs/invisible) | Use `'size' => 'invisible'` |
25+
| **Version** | **Docs** | **Notes** |
26+
|----------------------|-------------------------------------------------------------------|-----------------------------------|
27+
| **v3** (recommended) | [V3 Docs](https://developers.google.com/recaptcha/docs/v3) | |
28+
| **v3** (enterprise) | [V3 Docs](https://developers.google.com/recaptcha/docs/v3) | Use `'version' => 'v3-enterprise'` |
29+
| **v2** | [V2 Docs](https://developers.google.com/recaptcha/docs/display) | |
30+
| **v2 invisible** | [V2 Docs](https://developers.google.com/recaptcha/docs/invisible) | Use `'size' => 'invisible'` |
3031

3132
Your options should reside in the `config/services.php` file:
3233

@@ -38,6 +39,7 @@ Your options should reside in the `config/services.php` file:
3839
'secret_key' => env('GOOGLE_RECAPTCHA_SECRET_KEY'),
3940
'version' => 'v3',
4041
'score' => 0.5, // An integer between 0 and 1, that indicates the minimum score to pass the Captcha challenge.
42+
'endpoint' => 'https://www.google.com/recaptcha/api/siteverify', // For enterprise users, fill in your URL from Google Console.
4143
],
4244
],
4345

@@ -102,6 +104,10 @@ Secondly, add the new directive `wire:recaptcha` to the form element that you wa
102104
<!-- Add the `wire:recaptcha` Livewire directive -->
103105
<form wire:submit="save" wire:recaptcha>
104106
<!-- The rest of your form -->
107+
108+
<!-- When using version 2, insert the placeholder element -->
109+
<div id="g-recaptcha-element"></div>
110+
105111
<button type="submit">Submit</button>
106112
</form>
107113

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"license": "MIT",
1212
"require": {
1313
"php": "^8.2",
14-
"livewire/livewire": "^3.0"
14+
"livewire/livewire": "^3.0|^4.0"
1515
},
1616
"require-dev": {
1717
"friendsofphp/php-cs-fixer": "^3.8",
18-
"larastan/larastan": "^2.9",
19-
"orchestra/testbench": "^9.0",
18+
"larastan/larastan": "^2.9|^3.0",
19+
"orchestra/testbench": "^9.0|^10.0",
2020
"phpunit/phpunit": "^11.1"
2121
},
2222
"autoload": {

src/LivewireRecaptcha.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class LivewireRecaptcha
1515
* @return string
1616
*/
1717
public static function directive(
18-
string $version = null,
19-
string $siteKey = null,
20-
string $theme = null,
21-
string $size = null,
18+
?string $version = null,
19+
?string $siteKey = null,
20+
?string $theme = null,
21+
?string $size = null,
2222
): string {
2323
$version ??= config('services.google.recaptcha.version') ?? 'v3';
2424

src/ValidatesRecaptcha.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ class ValidatesRecaptcha extends LivewireAttribute
1616
public function __construct(
1717
public ?string $secretKey = null,
1818
public ?float $score = null,
19+
public ?string $endpoint = null,
1920
) {
2021
$this->secretKey ??= config('services.google.recaptcha.secret_key');
2122
$this->score ??= config('services.google.recaptcha.score') ?? 0.5;
23+
$this->endpoint ??= config('services.google.recaptcha.endpoint', 'https://www.google.com/recaptcha/api/siteverify');
2224
}
2325

2426
/**
@@ -28,8 +30,10 @@ public function __construct(
2830
*/
2931
public function call(array $params, Closure $returnEarly): void
3032
{
33+
assert(is_string($this->endpoint));
34+
3135
if (isset($this->component->gRecaptchaResponse)) {
32-
$response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
36+
$response = Http::asForm()->post($this->endpoint, [
3337
'secret' => $this->secretKey,
3438
'response' => $this->component->gRecaptchaResponse,
3539
'remoteip' => request()->ip(),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script>
2+
document.addEventListener('livewire:init', () => {
3+
Livewire.directive('recaptcha', ({ el, directive, component, cleanup }) => {
4+
const submitExpression = (() => {
5+
for (const attr of el.attributes) {
6+
if (attr.name.startsWith('wire:submit')) {
7+
return attr.value;
8+
}
9+
}
10+
})();
11+
12+
const onSubmit = (e) => {
13+
e.preventDefault();
14+
e.stopImmediatePropagation();
15+
16+
grecaptcha.enterprise.ready(async () => {
17+
const token = await grecaptcha.enterprise.execute(@json($siteKey), { action: 'submit' });
18+
19+
component.$wire.$set('gRecaptchaResponse', token).then(() => {
20+
Alpine.evaluate(el, "$wire." + submitExpression, { scope: { $event: e } });
21+
});
22+
});
23+
}
24+
25+
el.addEventListener('submit', onSubmit, { capture: true });
26+
});
27+
});
28+
</script>
29+
<script src="https://www.google.com/recaptcha/enterprise.js?render={{ $siteKey }}"></script>

0 commit comments

Comments
 (0)