Skip to content

Commit d258c5d

Browse files
committed
turnstile cleanup client side
1 parent 155c56c commit d258c5d

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

app/lib/turnstile.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def enabled?
1313
end
1414

1515
def verification_url
16-
'https://challenges.cloudflare.com/turnstile/v0/siteverify'
16+
::URI.parse('https://challenges.cloudflare.com/turnstile/v0/siteverify')
1717
end
1818
end
1919

@@ -25,7 +25,7 @@ def call(response, remoteip)
2525
return true unless self.class.enabled?
2626
return false unless response
2727

28-
response = ::Net::HTTP.post_form(::URI.parse(self.class.verification_url), secret: self.class.secret_key, response:, remoteip:)
28+
response = ::Net::HTTP.post_form(self.class.verification_url, secret: self.class.secret_key, response:, remoteip:)
2929
logger.info("Turnstile response: #{response.body}")
3030
!!::JSON.parse(response.body).dig('success')
3131
end

app/views/application/_turnstile.html.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
}
1212
}
1313

14-
function hideHiddenElement() {
14+
<% if ::Turnstile.enabled? %>
15+
setTimeout(() => {
1516
const elem = getTurnstileHiddenElement();
1617
if (elem) {
1718
elem.setAttribute("hidden", true)
1819
}
19-
}
20-
21-
<% if ::Turnstile.enabled? %>
22-
setTimeout(hideHiddenElement, 100);
20+
}, 100);
2321
<% end %>
2422
</script>
2523

0 commit comments

Comments
 (0)