card-mod-recaptcha 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 401f01a508d89f16d576d0eba9be296ed70c94118f06a3a2eabbd2c4b53c7e63
4
- data.tar.gz: 62119671698e2adf4fffa4c84737eb0304efe8ffbb5779c25a1f83df2e04b29b
3
+ metadata.gz: ad98d42ca508bbf0d27cb2d653751ace79557fb26816f96255b0f38632b1695d
4
+ data.tar.gz: 397183d1b43f25cdf8a854911d57784fa6f90255adbea4c4d9bfc977a651a668
5
5
  SHA512:
6
- metadata.gz: 13639bf7512b46965b7e6123de531057dd9282b00f77048ddc35eaaa8c2b22a2aef348c76f076c2bb75db19191531b3e7683f5138e71e48c867d6a693b2608a5
7
- data.tar.gz: 4279e90ced604d1e0e997c7517b1b1320671f2c895a0d0949a4a9e118bc90a9d5dcca288c4336039c6d19ff3b339fb0064900087f168a2a6cd62cc22da468f48
6
+ metadata.gz: 1ca552cca2c85b058155509d46c11102f529ae421658c0655bcbe646842a8514a04bdf02560629cc53aa8298830fc5fe113e1de643be3d4f7ac1c4ac66eef0bd
7
+ data.tar.gz: 3583498a9b11836546e714cc13b916d5ccd301b79d4b245f58f78a669cb0cd369102e3e37a79bab0403fa337a8ebac03c6a320ce5935cfe96478da0850edb960
@@ -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,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
@@ -2,34 +2,43 @@
2
2
 
3
3
  require "recaptcha"
4
4
 
5
- # This initializer module is mostly here to avoid adding methods/vars to the Object
6
- # namespace
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
+ #
7
15
  module RecaptchaCard
8
16
  @deprecated = {
9
- recaptcha_site_key: :recaptcha_public_key,
10
- recaptcha_secret_key: :recaptcha_private_key
17
+ site_key: :recaptcha_public_key,
18
+ secret_key: :recaptcha_private_key
11
19
  }
12
20
  @defaults = {
13
- recaptcha_site_key: "6LdoqpgUAAAAAEdhJ4heI1h3XLlpXcDf0YubriCG",
14
- recaptcha_secret_key: "6LdoqpgUAAAAAP4Sz1L5PY6VKrum_RFxq4-awj4BH"
21
+ site_key: "6LdoqpgUAAAAAEdhJ4heI1h3XLlpXcDf0YubriCG",
22
+ secret_key: "6LdoqpgUAAAAAP4Sz1L5PY6VKrum_RFxq4-awj4BH"
15
23
  }
16
24
 
17
- mattr_accessor :using_card_defaults
18
-
19
25
  class << self
20
26
  def load_recaptcha_config setting
21
- setting = "recaptcha_#{setting}".to_sym
22
- Cardio.config.send "#{setting}=", recaptcha_setting_value(setting)
27
+ full_setting = "recaptcha_#{setting}".to_sym
28
+ Cardio.config.send "#{full_setting}=",
29
+ recaptcha_setting_value(setting, full_setting)
23
30
  end
24
31
 
25
32
  def using_defaults?
26
- Cardio.config.recaptcha_site_key == @defaults[:recaptcha_site_key]
33
+ Cardio.config.recaptcha_site_key == @defaults[:site_key]
27
34
  end
28
35
 
36
+ private
37
+
29
38
  # 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)
39
+ def recaptcha_setting_value setting, full_setting
40
+ card_value(full_setting) || # card content
41
+ config_value(full_setting) || # application.rb (current setting)
33
42
  config_value(@deprecated[setting]) || # application.rb (deprecated setting)
34
43
  @defaults[setting]
35
44
  end
@@ -39,9 +48,11 @@ module RecaptchaCard
39
48
  end
40
49
 
41
50
  def card_value setting
42
- return unless Card::Codename.exist? setting # prevents breakage in migrations
51
+ # prevent breakage in migrations
52
+ return unless Card::Codename.exist?(:recaptcha_settings) &&
53
+ Card::Codename.exist?(setting)
43
54
 
44
- value = Card[setting]&.content
55
+ value = setting.card&.content
45
56
  value if value.present?
46
57
  end
47
58
  end
@@ -52,7 +63,7 @@ ActiveSupport.on_load :after_card do
52
63
  %i[site_key secret_key].each do |setting|
53
64
  config.send "#{setting}=", RecaptchaCard.load_recaptcha_config(setting)
54
65
  end
55
- config.verify_url = "https://www.google.com/recaptcha/api/siteverify"
66
+ config.verify_url = Cardio.config.recaptcha_verify_url
56
67
  end
57
68
  end
58
69
 
@@ -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
@@ -15,7 +15,7 @@ end
15
15
 
16
16
  def recaptcha_on?
17
17
  recaptcha_keys? &&
18
- Env[:controller] &&
18
+ Env.controller &&
19
19
  !Auth.signed_in? &&
20
20
  !Auth.always_ok? &&
21
21
  !Auth.needs_setup? &&
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  event :recaptcha, :validate, when: :validate_recaptcha? do
51
51
  handle_recaptcha_config_errors do
52
- Env[:recaptcha_used] = true
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 && !Env[:recaptcha_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
File without changes
data/set/self/captcha.rb CHANGED
@@ -3,3 +3,11 @@ setting_opts group: :permission,
3
3
  help_text: "Anti-spam setting. Requires non-signed-in users to complete a "\
4
4
  "[[http://decko.org/captcha|captcha]] before adding or editing "\
5
5
  "cards (where permitted)."
6
+
7
+ def captcha_used?
8
+ !@captcha_used.nil?
9
+ end
10
+
11
+ def captcha_used!
12
+ @captcha_used = true
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.1
4
+ version: 0.15.0
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-04 00:00:00.000000000 Z
13
+ date: 2023-01-04 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.1
21
+ version: 1.105.0
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.1
28
+ version: 1.105.0
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
+ - assets/script/recaptcha.js.coffee
51
+ - data/files/mod_recaptcha_script_asset_output/file.js
52
+ - data/real.yml
50
53
  - init/late/recaptcha.rb
54
+ - lib/card/mod/recaptcha.rb
51
55
  - locales/de.yml
52
56
  - locales/en.yml
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,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