class Object
Constants
- RECAPTCHA_ERROR_CODES
Public Instance Methods
add_recaptcha_errors(error_codes)
click to toggle source
# File set/all/recaptcha.rb, line 25 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
add_recaptcha_keys_link()
click to toggle source
# File set/self/admin_info.rb, line 24 def add_recaptcha_keys_link Card[:recaptcha_settings]&.format&.edit_link link_text: t(:recaptcha_captcha_keys) end
card_form_html_opts(action, opts={})
click to toggle source
Calls superclass method
# File set/all/recaptcha.rb, line 93 def card_form_html_opts action, opts={} super opts["data-recaptcha"] ||= "on" if recaptcha?(opts) opts end
handle_recaptcha_config_errors() { || ... }
click to toggle source
# File set/all/recaptcha.rb, line 57 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?()
click to toggle source
# File set/all/recaptcha.rb, line 9 def human? result = JSON.parse recaptcha_response return if recaptcha_success?(result) add_recaptcha_errors result["error-codes"] end
raw_help_text()
click to toggle source
# File set/self/recaptcha_settings.rb, line 2 def raw_help_text # LOCALIZE "Register your domain at Google's [[http://google.com/recaptcha|reCAPTCHA service]] "\ "and enter your site key and secret key below.<br>"\ "If you want to turn catchas off then change all [[*captcha|captcha rules]] to 'no'." end
recaptcha?(opts)
click to toggle source
# File set/all/recaptcha.rb, line 99 def recaptcha? opts card.recaptcha_on? && opts[:recaptcha] != :off end
recaptcha_config_issues?()
click to toggle source
# File set/self/admin_info.rb, line 3 def recaptcha_config_issues? RecaptchaCard.using_defaults? end
recaptcha_config_issues_message()
click to toggle source
# File set/self/admin_info.rb, line 8 def recaptcha_config_issues_message wrap_with :p do if Card::Env.localhost? # %(Your captcha is currently working with temporary settings. # This is fine for a local installation, but you will need new # recaptcha keys if you want to make this site public.) t :recaptcha_captcha_temp, recaptcha_link: add_recaptcha_keys_link else # %(You are configured to use [[*captcha]], but for that to work # you need new recaptcha keys.) t :recaptcha_captcha_keys, recaptcha_link: add_recaptcha_keys_link, captcha_link: link_to_card(:captcha) end end end
recaptcha_keys?()
click to toggle source
# File set/all/recaptcha.rb, line 46 def recaptcha_keys? Card.config.recaptcha_site_key && Card.config.recaptcha_secret_key end
recaptcha_on?()
click to toggle source
# File set/all/recaptcha.rb, line 16 def recaptcha_on? recaptcha_keys? && Env[:controller] && !Auth.signed_in? && !Auth.always_ok? && !Auth.needs_setup? && Card::Rule.toggle(rule(:captcha)) end
recaptcha_response()
click to toggle source
# File set/all/recaptcha.rb, line 41 def recaptcha_response ::Recaptcha.get({ secret: Card.config.recaptcha_secret_key, response: Env.params[:recaptcha_token] }, {}) end
recaptcha_script_url()
click to toggle source
# File set/all/recaptcha.rb, line 83 def recaptcha_script_url "https://www.google.com/recaptcha/api.js?render=#{Card.config.recaptcha_site_key}" end
recaptcha_success?(result)
click to toggle source
# File set/all/recaptcha.rb, line 35 def recaptcha_success? result result["success"] && (result["score"].to_f >= Cardio.config.recaptcha_minimum_score) && (result["action"].to_sym == action.to_sym) end
recaptcha_token(action)
click to toggle source
# File set/all/recaptcha.rb, line 73 def recaptcha_token action output [ javascript_include_tag(recaptcha_script_url), hidden_field_tag("recaptcha_token", "", "data-site-key": Card.config.recaptcha_site_key, "data-action": action, class: "_recaptcha-token") ] end
validate_recaptcha?()
click to toggle source
# File set/all/recaptcha.rb, line 68 def validate_recaptcha? !@supercard && !Env[:recaptcha_used] && recaptcha_on? end