|
11 | 11 |
|
12 | 12 | </br> |
13 | 13 |
|
14 | | -__Filament Turnstile__, is a plugin to help you implement the Cloudflare turnstile. |
| 14 | +**Filament Turnstile** is an essential plugin designed to seamlessly integrate Cloudflare's turnstile into your applications. |
15 | 15 |
|
16 | | -This plugin uses [Laravel Turnstile](https://github.com/coderflexx/laravel-turnstile) Behind the scene, you can head to the page __README__ to learn more. |
| 16 | +This plugin uses [Laravel Turnstile](https://github.com/coderflexx/laravel-turnstile) under the hood. For detailed information, explore the [Laravel Turnstile README](https://github.com/coderflexx/laravel-turnstile). |
17 | 17 |
|
18 | 18 | ## Installation |
19 | | -You can install the package via composer: |
20 | | - |
| 19 | +Install the package via Composer: |
21 | 20 |
|
22 | 21 | ```bash |
23 | 22 | composer require coderflex/filament-turnstile |
24 | 23 | ``` |
25 | 24 |
|
| 25 | +For users still on **Filament V2**, install the package using: |
| 26 | + |
| 27 | +```bash |
| 28 | +composer require coderflex/filament-turnstil "^1.0" |
| 29 | +``` |
26 | 30 |
|
27 | 31 | ## Turnstile Keys |
28 | | -To be able to use __Cloudflare Turnstile__, you need to get the `SiteKey`, and the `SecretKey` from your [Cloudflare dashboard](https://developers.cloudflare.com/turnstile/get-started/#get-a-sitekey-and-secret-key) |
| 32 | +To utilize **Cloudflare Turnstile**, obtain your `SiteKey` and `SecretKey` from your Cloudflare Dashboard. |
29 | 33 |
|
30 | | -After Generating the __keys__, use `TURNSTILE_SITE_KEY`, and `TURNSTILE_SECRET_KEY` in your `.env` file |
| 34 | +Refer to the [documentation](https://developers.cloudflare.com/turnstile/get-started/#get-a-sitekey-and-secret-key) for detailed instructions. |
31 | 35 |
|
32 | | -```.env |
33 | | -TURNSTILE_SITE_KEY=2x00000000000000000000AB |
34 | | -TURNSTILE_SECRET_KEY=2x0000000000000000000000000000000AA |
| 36 | +After generating the **keys**, include them in your `.env` file using the following format: |
| 37 | + |
| 38 | +```env |
| 39 | +TURNSTILE_SITE_KEY=1x00000000000000000000AA |
| 40 | +TURNSTILE_SECRET_KEY=1x0000000000000000000000000000000AA |
35 | 41 | ``` |
36 | 42 |
|
37 | | -If you want to test the widget, you can use the [Dummy site keys and secret keys](https://developers.cloudflare.com/turnstile/reference/testing/) that Cloudflare provides. |
| 43 | +For testing purposes, you can use [Dummy site keys and secret keys](https://developers.cloudflare.com/turnstile/reference/testing/) provided by Cloudflare. |
38 | 44 |
|
39 | 45 | ## Usage |
40 | 46 |
|
41 | | -The usage of this plugin, is really straight - forward. In your form, use the following code: |
| 47 | +Utilizing this plugin is incredibly straightforward. In your form, incorporate the following code: |
42 | 48 |
|
43 | 49 | ```php |
44 | | -... |
45 | 50 | use Coderflex\FilamentTurnstile\Forms\Components\Turnstile; |
46 | 51 |
|
47 | | -... |
48 | | - Turnstile::make('captcha') |
49 | | - ->theme('auto') |
50 | | - ->language('fr') |
51 | | - ->size('normal'), |
| 52 | +Turnstile::make('captcha') |
| 53 | + ->theme('auto') // accepts light, dark, auto |
| 54 | + ->language('en-US') // see below |
| 55 | + ->size('normal'), // accepts normal, compact |
52 | 56 | ``` |
53 | 57 |
|
54 | | -The `Turnstile` field, has few options to use. You can learn more about them in [the Cloudflare configuration section](https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#configurations) |
| 58 | +For a list of supported languages, refer to the [supported languages section](https://developers.cloudflare.com/turnstile/reference/supported-languages/). |
| 59 | + |
| 60 | +The `Turnstile` field offers various options; you can learn more about them in [the Cloudflare configuration section](https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#configurations). |
| 61 | + |
55 | 62 |
|
56 | | -## Real Life Example: |
57 | | -In order to use __Turnstile__ captcha with the `Login` page in filament, use the following steps: |
| 63 | +## Real-Life Example: |
58 | 64 |
|
59 | | -Create a new `App/Filament/Pages/Login.php` class |
| 65 | +To implement the **Turnstile** captcha with the `Login` page in Filament, follow these steps: |
| 66 | + |
| 67 | +Create a new `App/Filament/Pages/Auth/Login.php` class: |
60 | 68 |
|
61 | 69 | ```php |
62 | | -<?php |
63 | 70 |
|
64 | | -namespace App\Filament\Pages; |
| 71 | +namespace App\Filament\Pages\Auth; |
65 | 72 |
|
66 | 73 | use Coderflex\FilamentTurnstile\Forms\Components\Turnstile; |
| 74 | +use Filament\Forms\Form; |
| 75 | +use Filament\Http\Responses\Auth\Contracts\LoginResponse; |
| 76 | +use Filament\Pages\Auth\Login as AuthLogin; |
67 | 77 |
|
68 | | -class Login extends \Filament\Http\Livewire\Auth\Login |
| 78 | +class Login extends AuthLogin |
69 | 79 | { |
70 | | - protected function getFormSchema(): array |
| 80 | + /** |
| 81 | + * @return array<int|string, string|Form> |
| 82 | + */ |
| 83 | + protected function getForms(): array |
71 | 84 | { |
72 | | - return array_merge( |
73 | | - parent::getFormSchema(), |
74 | | - [ |
75 | | - Turnstile::make('cf-captcha') |
76 | | - ->theme('auto') |
77 | | - ->language('en-US') |
78 | | - ->size('normal'), |
79 | | - ] |
80 | | - ); |
| 85 | + return [ |
| 86 | + 'form' => $this->form( |
| 87 | + $this->makeForm() |
| 88 | + ->schema([ |
| 89 | + $this->getEmailFormComponent(), |
| 90 | + $this->getPasswordFormComponent(), |
| 91 | + $this->getRememberFormComponent(), |
| 92 | + Turnstile::make('captcha') |
| 93 | + ->label('Captcha') |
| 94 | + ->theme('auto'), |
| 95 | + ]) |
| 96 | + ->statePath('data'), |
| 97 | + ), |
| 98 | + ]; |
81 | 99 | } |
82 | 100 | } |
83 | 101 | ``` |
84 | 102 |
|
85 | | -Then override the `Login` class in the `filament.php` config file. |
| 103 | +Then, override the `login()` method in your `PanelProvider` (e.g., `AdminPanelProvider`): |
86 | 104 |
|
87 | 105 | ```php |
88 | | - return [ |
89 | | - .... |
90 | | - 'auth' => [ |
91 | | - 'guard' => env('FILAMENT_AUTH_GUARD', 'web'), |
92 | | - 'pages' => [ |
93 | | - 'login' => \App\Filament\Pages\Login::class, |
94 | | - ], |
95 | | - ], |
96 | | - ... |
97 | | - ] |
| 106 | +namespace App\Providers\Filament; |
| 107 | + |
| 108 | +use App\Filament\Auth\Login; |
| 109 | +use Filament\Panel; |
| 110 | +use Filament\PanelProvider; |
| 111 | + |
| 112 | +class AdminPanelProvider extends PanelProvider |
| 113 | +{ |
| 114 | + public function panel(Panel $panel): Panel |
| 115 | + { |
| 116 | + return $panel |
| 117 | + ->default() |
| 118 | + ->id('admin') |
| 119 | + ->path('admin') |
| 120 | + ->login(Login::class); // override the login page class. |
| 121 | + ... |
| 122 | + } |
| 123 | +} |
98 | 124 | ``` |
99 | 125 | ## Testing |
100 | 126 |
|
|
0 commit comments