cloudflare-turnstile-rails 0.11.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -10
- data/lib/cloudflare/turnstile/rails/controller_methods.rb +3 -1
- data/lib/cloudflare/turnstile/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 167722dcdc89fe5d682e584a48fc218d3a6839225333f4a5cad66ec81a37ada9
|
|
4
|
+
data.tar.gz: f07de910ba89fea39e55a0389552b4cf6485419f928b460e89f025d7ee2af22a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d7de00b3c2196a250e14a625168937203a7550d8850115379cc65c11d669df19604e5f0762f47747384ec558c53311f7425820b619e2db3de6eb10ab766a5191
|
|
7
|
+
data.tar.gz: 9120147af25bd3dcc6cf3c753b08e70b89a5b821f66eb2230edb17775361266cc4d6a5736303a30769593dd45d021d150b09cc1c95710e0437560bbe2f50e124
|
data/README.md
CHANGED
|
@@ -89,7 +89,7 @@ Supports `Rails >= 5.0` with `Ruby >= 2.6.0`.
|
|
|
89
89
|
That's it! Though it is recommended to match your `theme` and `language` to your app's design and locale:
|
|
90
90
|
|
|
91
91
|
```erb
|
|
92
|
-
<%= cloudflare_turnstile_tag data: { theme: '
|
|
92
|
+
<%= cloudflare_turnstile_tag data: { theme: 'light', language: 'en' } %>
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
* For all available **data-**\* options (e.g., `action`, `cdata`, `theme`, etc.), refer to the official Cloudflare client-side rendering docs:
|
|
@@ -101,17 +101,31 @@ Supports `Rails >= 5.0` with `Ruby >= 2.6.0`.
|
|
|
101
101
|
|
|
102
102
|
#### Simple Validation
|
|
103
103
|
|
|
104
|
-
* To validate a Turnstile response in your controller, use either `valid_turnstile?` or `turnstile_valid?`. Both methods behave identically and return a `boolean`. The `model` parameter is optional
|
|
104
|
+
* To validate a Turnstile response in your controller, use either `valid_turnstile?` or `turnstile_valid?`. Both methods behave identically and return a `boolean`. The `model` parameter is optional:
|
|
105
105
|
|
|
106
106
|
```ruby
|
|
107
107
|
if valid_turnstile?(model: @user)
|
|
108
108
|
# Passed: returns true
|
|
109
109
|
else
|
|
110
|
-
# Failed: returns false, adds errors to @user
|
|
110
|
+
# Failed: returns false, adds errors to @user.errors
|
|
111
111
|
render :new, status: :unprocessable_entity
|
|
112
112
|
end
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
* When **no model is provided** and verification fails, `valid_turnstile?` automatically sets `flash[:alert]` with the error message. This is useful for redirect-based flows:
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
def create
|
|
119
|
+
if valid_turnstile?
|
|
120
|
+
# Passed: no model needed
|
|
121
|
+
redirect_to dashboard_path, notice: 'Success!'
|
|
122
|
+
else
|
|
123
|
+
# Failed: flash[:alert] is automatically set
|
|
124
|
+
redirect_to contact_path
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
```
|
|
128
|
+
|
|
115
129
|
* You may also pass additional **siteverify** parameters (e.g., `secret`, `response`, `remoteip`, `idempotency_key`) supported by Cloudflare's API:
|
|
116
130
|
[Cloudflare Server-Side Validation Parameters](https://developers.cloudflare.com/turnstile/get-started/server-side-validation/#required-parameters)
|
|
117
131
|
|
|
@@ -134,13 +148,14 @@ Supports `Rails >= 5.0` with `Ruby >= 2.6.0`.
|
|
|
134
148
|
result = verify_turnstile(model: @user)
|
|
135
149
|
```
|
|
136
150
|
|
|
137
|
-
This method
|
|
151
|
+
This method adds errors to the model if verification fails, but unlike `valid_turnstile?`, it does **not** automatically set flash messages. This gives you full control over error handling:
|
|
138
152
|
|
|
139
153
|
```ruby
|
|
140
154
|
if result.success?
|
|
141
155
|
# Passed
|
|
142
156
|
else
|
|
143
|
-
# Failed —
|
|
157
|
+
# Failed — handle errors yourself
|
|
158
|
+
flash[:error] = "Custom message: #{result.errors.join(', ')}"
|
|
144
159
|
end
|
|
145
160
|
```
|
|
146
161
|
|
|
@@ -177,7 +192,7 @@ The `cloudflare_turnstile_tag` helper injects the Turnstile widget and accompany
|
|
|
177
192
|
|
|
178
193
|
### Turbo & Turbo Streams Support
|
|
179
194
|
|
|
180
|
-
All widgets will re‑initialize automatically on
|
|
195
|
+
All widgets will re‑initialize automatically on Turbo navigations (`turbo:render`) and on `<turbo-stream>` renders (`turbo:before-stream-render`) — no extra wiring needed.
|
|
181
196
|
|
|
182
197
|
### Turbolinks Support
|
|
183
198
|
|
|
@@ -323,11 +338,8 @@ If you run into any issues after upgrading Rails, please [open an issue](https:/
|
|
|
323
338
|
|
|
324
339
|
## Troubleshooting
|
|
325
340
|
|
|
326
|
-
**Duplicate Widgets**
|
|
327
|
-
- If more than one Turnstile widget appears in the same container, this indicates a bug in the gem—please [open an issue](https://github.com/vkononov/cloudflare-turnstile-rails/issues) so it can be addressed.
|
|
328
|
-
|
|
329
341
|
**Explicit Rendering**
|
|
330
|
-
- If you've configured explicit mode (`config.render = 'explicit'`
|
|
342
|
+
- If you've configured explicit mode (`config.render = 'explicit'`) but widgets still auto-render, override the default container class:
|
|
331
343
|
|
|
332
344
|
```erb
|
|
333
345
|
<%= cloudflare_turnstile_tag class: nil %>
|
|
@@ -19,7 +19,9 @@ module Cloudflare
|
|
|
19
19
|
|
|
20
20
|
def valid_turnstile?(model: nil, **opts)
|
|
21
21
|
response = verify_turnstile(model: model, **opts)
|
|
22
|
-
response.is_a?(VerificationResponse) && response.success?
|
|
22
|
+
success = response.is_a?(VerificationResponse) && response.success?
|
|
23
|
+
flash[:alert] = ErrorMessage.default if !success && model.nil?
|
|
24
|
+
success
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
alias turnstile_valid? valid_turnstile?
|