Module: Card::Set::All::Recaptcha
- Extended by:
- Card::Set
- Defined in:
- platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb
Overview
Set: All cards (Recaptcha)
Defined Under Namespace
Modules: HtmlFormat
Constant Summary collapse
- RECAPTCHA_ERROR_CODES =
LOCALIZE
{ # LOCALIZE "missing-input-secret" => "secret parameter is missing", "invalid-input-secret" => "secret parameter is invalid or malformed", "missing-input-response" => "response parameter is missing", "invalid-input-response" => "response parameter is invalid or malformed", "bad-request" => "request is invalid or malformed" }
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Constants included from Event::Api
Class Method Summary collapse
Instance Method Summary collapse
-
#add_recaptcha_errors(error_codes) ⇒ Object
-
#event: recaptcha ⇒ Object
-
#handle_recaptcha_config_errors ⇒ Object
-
#human? ⇒ Boolean
-
#recaptcha_keys? ⇒ Boolean
-
#recaptcha_on? ⇒ Boolean
-
#recaptcha_response ⇒ Object
-
#recaptcha_success?(result) ⇒ Boolean
-
#validate_recaptcha? ⇒ Boolean
Methods included from Card::Set
Methods included from I18nScope
Methods included from Registrar
#extended, #finalize_load, #process_base_modules, #register_set
Methods included from Helpers
#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name
Methods included from Card::Set::AdvancedApi
#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Class Method Details
.source_location ⇒ Object
7 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/mod/recaptcha/set/all/recaptcha.rb"; end |
Instance Method Details
#add_recaptcha_errors(error_codes) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 32 def add_recaptcha_errors error_codes if error_codes.present? error_codes.each do |code| errors.add :recaptcha, RECAPTCHA_ERROR_CODES.fetch(code, code) end else errors.add :recaptcha, "Looks like you are not a human" # LOCALIZE end end |
#event: recaptcha ⇒ Object
57 58 59 60 61 62 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 57 event :recaptcha, :validate, when: :validate_recaptcha? do handle_recaptcha_config_errors do :captcha.card.captcha_used! human? end end |
#handle_recaptcha_config_errors ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 64 def handle_recaptcha_config_errors case Env.params[:recaptcha_token] when "grecaptcha-undefined" errors.add "recaptcha", "needs correct v3 configuration" # LOCALILZE when "recaptcha-token-field-missing" raise Card::Error, "recaptcha token field missing" # LOCALILZE else yield end end |
#human? ⇒ Boolean
16 17 18 19 20 21 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 16 def human? result = JSON.parse recaptcha_response return if recaptcha_success?(result) add_recaptcha_errors result["error-codes"] end |
#recaptcha_keys? ⇒ Boolean
53 54 55 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 53 def recaptcha_keys? Card.config.recaptcha_site_key && Card.config.recaptcha_secret_key end |
#recaptcha_on? ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 23 def recaptcha_on? recaptcha_keys? && Env.controller && !Auth.signed_in? && !Auth.always_ok? && !Auth.needs_setup? && Card::Rule.toggle(rule(:captcha)) end |
#recaptcha_response ⇒ Object
48 49 50 51 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 48 def recaptcha_response ::Recaptcha.get({ secret: Card.config.recaptcha_secret_key, response: Env.params[:recaptcha_token] }, {}) end |
#recaptcha_success?(result) ⇒ Boolean
42 43 44 45 46 |
# File 'platypus/tmp/set/gem-defaults/mod032-recaptcha/all/recaptcha.rb', line 42 def recaptcha_success? result result["success"] && (result["score"].to_f >= Cardio.config.recaptcha_minimum_score) && (result["action"].to_sym == action.to_sym) end |