turnstiled 0.1.0 → 0.1.2

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: da753c2bafbc45fa1b878958ab03e1131979c8cfa0299a0bb2cbdd48594da72b
4
- data.tar.gz: 7f6a09f9e461ca65f612d1a5e1dc3259b6a88d70f6c542f42a85ad13b3b93845
3
+ metadata.gz: 8459e2a83594eee0f04026d446a3696225b29af2b8bb5f749104d5179bd7098c
4
+ data.tar.gz: e14e6ff91ae43a3f515e729c90a5bf194935241553d3bc6b47157e0e491d9827
5
5
  SHA512:
6
- metadata.gz: 99c3f6895fa3817093d3a3eb35da430d0877b49dcaf0e80b6a08524bb9552920fcdff7d7355525d5513ca370fba4a74cc8405a65d68951a0710a3c0aa53521bd
7
- data.tar.gz: 802b6644f991b9fa2875bff02422f0865bdab972b320472c09cb4d50df3fcb85834c5b720cf1538e2f4f598fd2be3a45733e2727ce2b4ce9961c320ca5679d98
6
+ metadata.gz: e5ff34b9c984a69069bee6a2d15c8cac54dff142832a297d2d90d020f041fa47ad527b2ec7465192672464e0f687726acc17e31e2f4e1487538854c05b7e30b7
7
+ data.tar.gz: cf1aeaa863d06b1d2e4fddcb0e418eeaddcae133a62691dc633e34fbeec0467970fa837642858f4973f4f4ed133f85f00f0ee06ec796ebc2a950ad890009bbb1
data/README.md CHANGED
@@ -1,28 +1,54 @@
1
- # Turnstiled
2
- Short description and motivation.
1
+ Turnstiled
2
+ ==========
3
3
 
4
- ## Usage
5
- How to use my plugin.
4
+ Turnstiled makes it easy to add the Cloudflare Turnstile Captcha to your Rails app.
6
5
 
7
- ## Installation
8
- Add this line to your application's Gemfile:
6
+ For development, it even inlucdes a Mock widget.
9
7
 
10
- ```ruby
8
+ Getting Usage
9
+ -------------
10
+
11
+ ### Installation
12
+
13
+ First install the gem by adding this line to your application's Gemfile:
14
+
15
+ ``` ruby
11
16
  gem "turnstiled"
12
17
  ```
13
18
 
14
- And then execute:
15
- ```bash
19
+ And executing:
20
+
21
+ ``` bash
16
22
  $ bundle
17
23
  ```
18
24
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install turnstiled
25
+ ### Configuration
26
+
27
+ Create a file called `config/initializers/turnstiled.rb` and add the following:
28
+
29
+ ``` ruby
30
+ Turnstiled.configure do |config|
31
+ config.api_key = "YOUR_API_KEY"
32
+ config.api_secret = "YOUR_API_SECRET"
33
+ end
22
34
  ```
23
35
 
24
- ## Contributing
25
- Contribution directions go here.
36
+ In your layout, add the widget to the head of the document:
37
+
38
+ ``` erb
39
+ <%= turnstiled_javascript_tag %>
40
+ ```
41
+
42
+ In test and development, it will include a mock widget that fires the callback after 2 seconds.
43
+
44
+ The mock widget will send the `cf-turnstile-response` parameter with a value of `1`.
45
+
46
+ In your controller, you also need to verify the response with the following:
47
+
48
+ ``` ruby
49
+ class PostsController < ApplicationController
50
+ verify_turnstile_requwst only: %i[create]
51
+ end
52
+ ```
26
53
 
27
- ## License
28
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
54
+ The `verify_turnstile_requwst` takes the same options as a `before_action` method call.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -1,14 +1,14 @@
1
1
  module Turnstiled
2
2
  class Engine < ::Rails::Engine
3
- initializer 'turnstiled.controller' do
3
+ initializer "turnstiled.controller" do
4
4
  ActiveSupport.on_load(:action_controller_base) { include Turnstiled::ControllerMethods }
5
5
  end
6
6
 
7
- initializer 'turnstiled.controller' do
7
+ initializer "turnstiled.controller" do
8
8
  ActiveSupport.on_load(:action_view) { include Turnstiled::ViewHelper }
9
9
  end
10
10
 
11
- initializer 'turnstiled.assets' do |app|
11
+ initializer "turnstiled.assets" do |app|
12
12
  app.config.assets.paths << root.join("app/javascript")
13
13
  end
14
14
  end
@@ -3,15 +3,15 @@
3
3
  module Turnstiled
4
4
  class Verifier
5
5
  def verify(request)
6
- return request.params['cf-turnstile-response'] == '1' if Turnstiled.mock
6
+ return request.params["cf-turnstile-response"] == "1" if Turnstiled.mock
7
7
 
8
- response = client.post('siteverify', {
8
+ response = client.post("siteverify", {
9
9
  secret: Turnstiled.site_secret,
10
- response: request.params['cf-turnstile-response'],
11
- remoteip: request.remote_ip,
10
+ response: request.params["cf-turnstile-response"],
11
+ remoteip: request.remote_ip
12
12
  })
13
13
 
14
- response.body.fetch('success', false)
14
+ response.body.fetch("success", false)
15
15
  end
16
16
 
17
17
  def client
@@ -23,10 +23,10 @@ module Turnstiled
23
23
 
24
24
  def client_options
25
25
  {
26
- url: 'https://challenges.cloudflare.com/turnstile/v0',
26
+ url: "https://challenges.cloudflare.com/turnstile/v0",
27
27
  request: {
28
- timeout: 3,
29
- },
28
+ timeout: 3
29
+ }
30
30
  }
31
31
  end
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module Turnstiled
2
- VERSION = "0.1.0"
2
+ VERSION = File.read(File.expand_path("../../../VERSION", __FILE__)).strip
3
3
  end
@@ -2,28 +2,28 @@
2
2
 
3
3
  module Turnstiled
4
4
  module ViewHelper
5
- def turnstile_tag(size: 'compact', **options)
5
+ def turnstile_tag(size: "compact", **options)
6
6
  options = options.deep_merge(
7
7
  class: "cf-turnstile #{options[:class]}",
8
8
  data: {
9
9
  sitekey: Turnstiled.site_key,
10
- controller: 'turnstile',
10
+ controller: "turnstile",
11
11
  turnstile_site_key_value: Turnstiled.site_key,
12
- size:,
12
+ size:
13
13
  }
14
14
  )
15
15
 
16
- content_tag(:div, '', options)
16
+ content_tag(:div, "", options)
17
17
  end
18
18
 
19
19
  def turnstile_javascript_tag
20
20
  if ::Turnstiled.mock
21
- javascript_include_tag('turnstiled/mock_turnstile_widget.js', defer: true, data: { turbo_track: 'reload' })
21
+ javascript_include_tag("turnstiled/mock_turnstile_widget.js", defer: true, data: { turbo_track: "reload" })
22
22
  else
23
- javascript_include_tag('https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit',
23
+ javascript_include_tag("https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",
24
24
  defer: true,
25
25
  data: {
26
- turbo_track: 'reload',
26
+ turbo_track: "reload"
27
27
  })
28
28
  end
29
29
  end
data/lib/turnstiled.rb CHANGED
@@ -2,9 +2,9 @@ require "turnstiled/version"
2
2
  require "turnstiled/engine"
3
3
 
4
4
  module Turnstiled
5
- autoload :ControllerMethods, 'turnstiled/controller_methods'
6
- autoload :ViewHelper, 'turnstiled/view_helper'
7
- autoload :Verifier, 'turnstiled/verifier'
5
+ autoload :ControllerMethods, "turnstiled/controller_methods"
6
+ autoload :ViewHelper, "turnstiled/view_helper"
7
+ autoload :Verifier, "turnstiled/verifier"
8
8
 
9
9
  mattr_accessor :site_key
10
10
  mattr_accessor :site_secret
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnstiled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Displayful
8
8
  - Henrik Hauge Bjørnskov
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2025-02-25 00:00:00.000000000 Z
@@ -15,22 +15,22 @@ dependencies:
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 7.0.0
21
18
  - - "~>"
22
19
  - !ruby/object:Gem::Version
23
20
  version: '7.0'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 7.0.0
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: 7.0.0
31
28
  - - "~>"
32
29
  - !ruby/object:Gem::Version
33
30
  version: '7.0'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 7.0.0
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: faraday
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +45,7 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- description:
48
+ description:
49
49
  email:
50
50
  - hb@displayful.co
51
51
  executables: []
@@ -55,6 +55,7 @@ files:
55
55
  - LICENSE
56
56
  - README.md
57
57
  - Rakefile
58
+ - VERSION
58
59
  - app/assets/config/turnstiled/manifest.js
59
60
  - app/javascript/turnstiled/controllers/turnstile_controller.js
60
61
  - app/javascript/turnstiled/mock_turnstile_widget.js
@@ -69,7 +70,7 @@ licenses:
69
70
  - MIT
70
71
  metadata:
71
72
  allowed_push_host: https://rubygems.org
72
- post_install_message:
73
+ post_install_message:
73
74
  rdoc_options: []
74
75
  require_paths:
75
76
  - lib
@@ -84,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  requirements: []
87
- rubygems_version: 3.0.3.1
88
- signing_key:
88
+ rubygems_version: 3.5.22
89
+ signing_key:
89
90
  specification_version: 4
90
91
  summary: Cloudflare Turnstile for Rails
91
92
  test_files: []