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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d8fd3cb77f097623954e01bb7b8edf603f88334dde368099b0da253aae0b2e0
4
- data.tar.gz: 134e4ea34f7e4a85e2a63971fd97bd3d709f388853a04b3efd67b247ff1bf7ba
3
+ metadata.gz: 167722dcdc89fe5d682e584a48fc218d3a6839225333f4a5cad66ec81a37ada9
4
+ data.tar.gz: f07de910ba89fea39e55a0389552b4cf6485419f928b460e89f025d7ee2af22a
5
5
  SHA512:
6
- metadata.gz: 1961d3464fa15763ac0c536d969ba5b825f191711f55a4b62067a81bdd83120337872b85d3492afb72065cc5e1d5e8180db27b88eed33457bec91bec533fa23d
7
- data.tar.gz: 5bf90db9a243711e0eced90efba52a5930914b035bc65cfde5d9e3981c418fd346e2d1bed4108cd58e12fd6706a302cc3c8a83d63b56a35835135b2463550139
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: 'auto', language: 'en' } %>
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 but recommended for automatic error handling:
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 still adds errors to the model if verification fails. You can query the response:
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 — inspect result.errors or result.raw
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 full and soft navigations (`turbo:load`), on `<turbo-stream>` renders (`turbo:before-stream-render`), and on DOM mutations — no extra wiring needed.
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'` or `cloudflare_turnstile_tag render: 'explicit'`) but widgets still auto-render, override the default container class:
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?
@@ -1,7 +1,7 @@
1
1
  module Cloudflare
2
2
  module Turnstile
3
3
  module Rails
4
- VERSION = '0.11.0'.freeze
4
+ VERSION = '1.0.0'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare-turnstile-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Kononov