card-mod-recaptcha 0.14.2 → 0.15.1

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: b12cb0a059983d63bdea8b6dbbe58d25fad2f05ed93c546974f8de1598b6c3ec
4
- data.tar.gz: eeda1e7905810763824b042079b779988bd4349c2aa5d16d5725426fcd4b08a6
3
+ metadata.gz: 8090ef02fab61efb5eafdf12a0a4a4ab698842f086fd119c4c283bc047546366
4
+ data.tar.gz: 7026b189a633445361680dfe4b00455a1dc46cac3f4423812958ffb92db33688
5
5
  SHA512:
6
- metadata.gz: c87aeacfbb72f72b2c3bf346f6fd5606562008d60136b47aa19894eb86e4fa864f9464c48e2c44b7bad3de75d69fa57c363935f9448f0dbc5dbd8d4d9486f4f2
7
- data.tar.gz: fd8ddc16d92999163f690a4c06ae0e9fd5a229859ac202c86f56c6607cb991e11904e7f31a2645992d18cfde43b7966db52b59494018d7058714b33a678c3a99
6
+ metadata.gz: a552fcfbba2ab8b55d8ca24593090031e8811595ef65ac97d640ff01b51c9800b1d9f1f1051e72b65803116405ea23075c2a95ef107671d73a3f2416a7c03b65
7
+ data.tar.gz: 8052d8a72482768a8f03400793692a16413e834eda8d72adfff2bc9c3b8fe9a968be2d194e04b422526dcdb545fd8eb5529dd92a86a3301a5908fab985f64e03
@@ -0,0 +1,41 @@
1
+ $(window).ready ->
2
+ $('body').on 'submit', 'form.slotter', (event)->
3
+ form = $(this)
4
+ handleRecaptcha form, event if form.data('recaptcha') == 'on'
5
+
6
+ handleRecaptcha = (form, event) ->
7
+ recaptcha = form.find("input._recaptcha-token")
8
+
9
+ if !recaptcha[0]?
10
+ # monkey error (bad form)
11
+ recaptcha.val "recaptcha-token-field-missing"
12
+ else if recaptcha.hasClass "_token-updated"
13
+ # recaptcha token is fine - continue submitting
14
+ recaptcha.removeClass "_token-updated"
15
+ else if !grecaptcha?
16
+ # shark error (probably recaptcha keys of pre v3 version)
17
+ recaptcha.val "grecaptcha-undefined"
18
+ else
19
+ updateRecaptchaToken(form, event)
20
+ # this stops the submit here
21
+ # and submits again when the token is ready
22
+
23
+ updateRecaptchaToken = (form, event) ->
24
+ recaptcha = form.find("input._recaptcha-token")
25
+
26
+ if !recaptcha[0]?
27
+ recaptcha.val "recaptcha-token-field-missing"
28
+ else if !grecaptcha?
29
+ recaptcha.val "grecaptcha-undefined"
30
+ else
31
+ event.stopPropagation() if event
32
+ executeGrecaptcha form, event, recaptcha
33
+ false
34
+
35
+ executeGrecaptcha = (form, event, recaptcha) ->
36
+ siteKey = recaptcha.data "site-key"
37
+ action = recaptcha.data "action"
38
+ grecaptcha.execute(siteKey, action: action).then (token) ->
39
+ recaptcha.val token
40
+ recaptcha.addClass "_token-updated"
41
+ form.submit() if event
@@ -0,0 +1,70 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require "recaptcha"
4
+
5
+ # This Recaptcha initializer handles the multiple ways in which the recaptcha site and
6
+ # secret key can be configured. These include:
7
+ #
8
+ # - in config files with config.recaptcha_site_key and config.recaptcha_secret_key
9
+ # (PREFERRED!)
10
+ # - via the :recaptcha_settings card
11
+ # - in config files with config.recaptcha_public_key and config.recaptcha_private_key
12
+ # (DEPRECATED!)
13
+ # - by using the defaults below (DEVELOPMENT ONLY)
14
+ #
15
+ module RecaptchaCard
16
+ @deprecated = {
17
+ site_key: :recaptcha_public_key,
18
+ secret_key: :recaptcha_private_key
19
+ }
20
+ @defaults = {
21
+ site_key: "6LdoqpgUAAAAAEdhJ4heI1h3XLlpXcDf0YubriCG",
22
+ secret_key: "6LdoqpgUAAAAAP4Sz1L5PY6VKrum_RFxq4-awj4BH"
23
+ }
24
+
25
+ class << self
26
+ def load_recaptcha_config setting
27
+ full_setting = "recaptcha_#{setting}".to_sym
28
+ Cardio.config.send "#{full_setting}=",
29
+ recaptcha_setting_value(setting, full_setting)
30
+ end
31
+
32
+ def using_defaults?
33
+ Cardio.config.recaptcha_site_key == @defaults[:site_key]
34
+ end
35
+
36
+ private
37
+
38
+ # card config overrides application.rb config overrides default
39
+ def recaptcha_setting_value setting, full_setting
40
+ card_value(full_setting) || # card content
41
+ config_value(full_setting) || # application.rb (current setting)
42
+ config_value(@deprecated[setting]) || # application.rb (deprecated setting)
43
+ @defaults[setting]
44
+ end
45
+
46
+ def config_value setting
47
+ Cardio.config.send setting
48
+ end
49
+
50
+ def card_value setting
51
+ # prevent breakage in migrations
52
+ return unless Card::Codename.exist?(:recaptcha_settings) &&
53
+ Card::Codename.exist?(setting)
54
+
55
+ value = setting.card&.content
56
+ value if value.present?
57
+ end
58
+ end
59
+ end
60
+
61
+ ActiveSupport.on_load :after_card do
62
+ Recaptcha.configure do |config|
63
+ %i[site_key secret_key].each do |setting|
64
+ config.send "#{setting}=", RecaptchaCard.load_recaptcha_config(setting)
65
+ end
66
+ config.verify_url = Cardio.config.recaptcha_verify_url
67
+ end
68
+ end
69
+
70
+ CardController.include ::Recaptcha::Verify
@@ -0,0 +1,2 @@
1
+ // recaptcha.js.coffee
2
+ (function(){var t,a,n;$(window).ready(function(){return $("body").on("submit","form.slotter",function(t){var n;if("on"===(n=$(this)).data("recaptcha"))return a(n,t)})}),a=function(t,a){var e;return null==(e=t.find("input._recaptcha-token"))[0]?e.val("recaptcha-token-field-missing"):e.hasClass("_token-updated")?e.removeClass("_token-updated"):"undefined"==typeof grecaptcha||null===grecaptcha?e.val("grecaptcha-undefined"):n(t,a)},n=function(a,n){var e;return null==(e=a.find("input._recaptcha-token"))[0]?e.val("recaptcha-token-field-missing"):"undefined"==typeof grecaptcha||null===grecaptcha?e.val("grecaptcha-undefined"):(n&&n.stopPropagation(),t(a,n,e),!1)},t=function(t,a,n){var e,c;return c=n.data("site-key"),e=n.data("action"),grecaptcha.execute(c,{action:e}).then(function(e){if(n.val(e),n.addClass("_token-updated"),a)return t.submit()})}}).call(this);
data/data/real.yml ADDED
@@ -0,0 +1,20 @@
1
+ - :name: "*captcha"
2
+ :type: :setting
3
+ :codename: captcha
4
+ - :name:
5
+ - :all
6
+ - :captcha
7
+ :type: :toggle
8
+ :content: '1'
9
+ - :name:
10
+ - :signup
11
+ - :type
12
+ - :captcha
13
+ :type: :toggle
14
+ :content: '1'
15
+ - :name: "*recaptcha settings"
16
+ :codename: recaptcha_settings
17
+ - :name: site key
18
+ :codename: site_key
19
+ - :name: secret key
20
+ :codename: secret_key
@@ -0,0 +1,10 @@
1
+ Cardio::Railtie.config.tap do |config|
2
+ config.recaptcha_public_key = nil # deprecated; use recaptcha_site_key instead
3
+ config.recaptcha_private_key = nil # deprecated; use recaptcha_secret_key instead
4
+
5
+ config.recaptcha_proxy = nil
6
+ config.recaptcha_site_key = nil
7
+ config.recaptcha_secret_key = nil
8
+ config.recaptcha_minimum_score = 0.5
9
+ config.recaptcha_verify_url = "https://www.google.com/recaptcha/api/siteverify"
10
+ end
@@ -0,0 +1,13 @@
1
+ event :validate_recaptcha_field, :validate, when: :recaptcha_setting? do
2
+ return if content.match?(/^[a-zA-Z0-9\-_]*$/)
3
+
4
+ errors.add :content, "invalid key" # LOCALIZE
5
+ end
6
+
7
+ event :set_recaptcha_site_key, :finalize, when: :recaptcha_setting? do
8
+ Card.config.send "recaptcha_#{codename}=", content
9
+ end
10
+
11
+ def recaptcha_setting?
12
+ left&.codename == :recaptcha_settings
13
+ end
data/set/all/recaptcha.rb CHANGED
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  event :recaptcha, :validate, when: :validate_recaptcha? do
51
51
  handle_recaptcha_config_errors do
52
- :captcha.card.used!
52
+ :captcha.card.captcha_used!
53
53
  human?
54
54
  end
55
55
  end
@@ -66,7 +66,9 @@ def handle_recaptcha_config_errors
66
66
  end
67
67
 
68
68
  def validate_recaptcha?
69
- !@supercard && !:captcha.card.used? && recaptcha_on?
69
+ return unless Card::Codename.exists? :captcha
70
+
71
+ !@supercard && !:captcha.card.captcha_used? && recaptcha_on?
70
72
  end
71
73
 
72
74
  format :html do
@@ -0,0 +1 @@
1
+ assign_type :toggle
@@ -0,0 +1 @@
1
+ include_set Abstract::RecaptchaSetting
@@ -0,0 +1 @@
1
+ include_set Abstract::RecaptchaSetting
data/set/self/captcha.rb CHANGED
@@ -4,10 +4,10 @@ setting_opts group: :permission,
4
4
  "[[http://decko.org/captcha|captcha]] before adding or editing "\
5
5
  "cards (where permitted)."
6
6
 
7
- def used?
8
- !@used.nil?
7
+ def captcha_used?
8
+ !@captcha_used.nil?
9
9
  end
10
10
 
11
- def used!
12
- @used = true
11
+ def captcha_used!
12
+ @captcha_used = true
13
13
  end
@@ -6,6 +6,10 @@ format :html do
6
6
  "If you want to turn captchas off then change all [[*captcha|captcha rules]] to 'no'."
7
7
  end
8
8
 
9
+ view :core do
10
+ [field_nest(:site_key), field_nest(:secret_key)]
11
+ end
12
+
9
13
  # def instructions title, steps
10
14
  # steps = list_tag steps, ordered: true
11
15
  # "#{title}#{steps}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-08 00:00:00.000000000 Z
13
+ date: 2023-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.104.2
21
+ version: 1.105.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.104.2
28
+ version: 1.105.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: recaptcha
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -47,16 +47,21 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
- - init/late/recaptcha.rb
51
- - locales/de.yml
52
- - locales/en.yml
50
+ - assets/script/recaptcha.js.coffee
51
+ - config/late/recaptcha.rb
52
+ - config/locales/de.yml
53
+ - config/locales/en.yml
54
+ - data/files/mod_recaptcha_script_asset_output/file.js
55
+ - data/real.yml
56
+ - lib/card/mod/recaptcha.rb
57
+ - set/abstract/recaptcha_setting.rb
53
58
  - set/all/recaptcha.rb
54
- - set/self/admin_info.rb
59
+ - set/right/captcha.rb
60
+ - set/right/secret_key.rb
61
+ - set/right/site_key.rb
62
+ - set/self/admin.rb
55
63
  - set/self/captcha.rb
56
- - set/self/recaptcha_proxy.rb
57
- - set/self/recaptcha_secret_key.rb
58
64
  - set/self/recaptcha_settings.rb
59
- - set/self/recaptcha_site_key.rb
60
65
  homepage: https://decko.org
61
66
  licenses:
62
67
  - GPL-3.0
@@ -67,6 +72,7 @@ metadata:
67
72
  wiki_uri: https://decko.org
68
73
  documentation_url: http://docs.decko.org/
69
74
  card-mod: recaptcha
75
+ card-mod-group: gem-defaults
70
76
  post_install_message:
71
77
  rdoc_options: []
72
78
  require_paths:
@@ -82,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
88
  - !ruby/object:Gem::Version
83
89
  version: '0'
84
90
  requirements: []
85
- rubygems_version: 3.2.15
91
+ rubygems_version: 3.3.11
86
92
  signing_key:
87
93
  specification_version: 4
88
94
  summary: recaptcha support for decko
@@ -1,59 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- require "recaptcha"
4
-
5
- # This initializer module is mostly here to avoid adding methods/vars to the Object
6
- # namespace
7
- module RecaptchaCard
8
- @deprecated = {
9
- recaptcha_site_key: :recaptcha_public_key,
10
- recaptcha_secret_key: :recaptcha_private_key
11
- }
12
- @defaults = {
13
- recaptcha_site_key: "6LdoqpgUAAAAAEdhJ4heI1h3XLlpXcDf0YubriCG",
14
- recaptcha_secret_key: "6LdoqpgUAAAAAP4Sz1L5PY6VKrum_RFxq4-awj4BH"
15
- }
16
-
17
- mattr_accessor :using_card_defaults
18
-
19
- class << self
20
- def load_recaptcha_config setting
21
- setting = "recaptcha_#{setting}".to_sym
22
- Cardio.config.send "#{setting}=", recaptcha_setting_value(setting)
23
- end
24
-
25
- def using_defaults?
26
- Cardio.config.recaptcha_site_key == @defaults[:recaptcha_site_key]
27
- end
28
-
29
- # card config overrides application.rb config overrides default
30
- def recaptcha_setting_value setting
31
- card_value(setting) || # card content
32
- config_value(setting) || # application.rb (current setting)
33
- config_value(@deprecated[setting]) || # application.rb (deprecated setting)
34
- @defaults[setting]
35
- end
36
-
37
- def config_value setting
38
- Cardio.config.send setting
39
- end
40
-
41
- def card_value setting
42
- return unless Card::Codename.exist? setting # prevents breakage in migrations
43
-
44
- value = Card[setting]&.content
45
- value if value.present?
46
- end
47
- end
48
- end
49
-
50
- ActiveSupport.on_load :after_card do
51
- Recaptcha.configure do |config|
52
- %i[site_key secret_key].each do |setting|
53
- config.send "#{setting}=", RecaptchaCard.load_recaptcha_config(setting)
54
- end
55
- config.verify_url = "https://www.google.com/recaptcha/api/siteverify"
56
- end
57
- end
58
-
59
- CardController.include ::Recaptcha::Verify
@@ -1,3 +0,0 @@
1
- event :set_recaptcha_proxy, :finalize do
2
- Card.config.recaptcha_proxy = content
3
- end
@@ -1,9 +0,0 @@
1
- event :validate_recaptcha_secret_key, :validate do
2
- return if content.match?(/^[a-zA-Z0-9\-_]*$/)
3
-
4
- errors.add :content, "invalid key" # LOCALIZE
5
- end
6
-
7
- event :set_recaptcha_secret_key, :finalize do
8
- Card.config.recaptcha_secret_key = content
9
- end
@@ -1,9 +0,0 @@
1
- event :validate_recaptcha_site_key, :validate do
2
- return if content.match?(/^[a-zA-Z0-9\-_]*$/)
3
-
4
- errors.add :content, "invalid key" # LOCALIZE
5
- end
6
-
7
- event :set_recaptcha_site_key, :finalize do
8
- Card.config.recaptcha_site_key = content
9
- end
File without changes
File without changes
File without changes