devise-cloudflare-turnstile 0.9.0 → 0.10.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b29bbe949d442bee08751e705b15350414748639b11d73296b84647a3492325e
|
|
4
|
+
data.tar.gz: 11159165db1ab0a0b9d1f3d09367c2ece59eff3d2fb875b1f84bd465be37c43e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9323f0c853e494ff79d6c1a7e02e0918e1931072a147c3fbeec1424bdc4966fdaeb34ae75fb333b605f28b22238416c728ba24638467b27380a17ac93ac70e82
|
|
7
|
+
data.tar.gz: ce5cf4f403126a3a8ac08fb8613ddeb300f21085aa0e47cf20a195cd78a3930fe0207ac12b530c4c0c53d936646247667a1cf5a9ccfaf70505824386fed4bc46
|
|
@@ -36,6 +36,8 @@ module Devise
|
|
|
36
36
|
self.resource ||= resource_class.new
|
|
37
37
|
return if valid_turnstile?(model: resource, **turnstile_verify_options)
|
|
38
38
|
|
|
39
|
+
restore_turnstile_submitted_values
|
|
40
|
+
|
|
39
41
|
# Sessions (and some other Devise views) do not render resource errors.
|
|
40
42
|
# Always surface the failure via flash so the user sees feedback.
|
|
41
43
|
flash.now[:alert] = ::Cloudflare::Turnstile::Rails::ErrorMessage.default
|
|
@@ -45,6 +47,34 @@ module Devise
|
|
|
45
47
|
render turnstile_failure_action, status: :unprocessable_entity
|
|
46
48
|
end
|
|
47
49
|
|
|
50
|
+
# Re-populate the resource with the values the user just submitted (minus
|
|
51
|
+
# passwords) so the re-rendered form keeps their input. We fail in a
|
|
52
|
+
# before_action, before Devise builds the resource from params, so
|
|
53
|
+
# without this the form would come back blank. Assigning to the
|
|
54
|
+
# in-memory resource is safe because the request halts here and the
|
|
55
|
+
# record is never saved.
|
|
56
|
+
def restore_turnstile_submitted_values
|
|
57
|
+
return unless respond_to?(:resource_name, true)
|
|
58
|
+
|
|
59
|
+
submitted = params[resource_name]
|
|
60
|
+
return unless submitted.respond_to?(:each_pair)
|
|
61
|
+
|
|
62
|
+
submitted.each_pair do |field, value|
|
|
63
|
+
next if field.to_s.include?('password')
|
|
64
|
+
next unless turnstile_scalar_value?(value)
|
|
65
|
+
|
|
66
|
+
setter = "#{field}="
|
|
67
|
+
resource.public_send(setter, value) if resource.respond_to?(setter)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Limits restoration to simple form values. Nested params (e.g. arrays or
|
|
72
|
+
# *_attributes hashes) are skipped because assigning them to the resource
|
|
73
|
+
# is error-prone, and Devise forms only use scalar fields anyway.
|
|
74
|
+
def turnstile_scalar_value?(value)
|
|
75
|
+
value.is_a?(String) || value.is_a?(Numeric) || [true, false].include?(value)
|
|
76
|
+
end
|
|
77
|
+
|
|
48
78
|
# Extra siteverify parameters forwarded to valid_turnstile?. Override in a
|
|
49
79
|
# custom Devise controller to add e.g. remoteip: request.remote_ip.
|
|
50
80
|
def turnstile_verify_options
|