module InvisibleCaptcha
Constants
- VERSION
Attributes
honeypots[RW]
injectable_styles[RW]
secret[RW]
sentence_for_humans[W]
spinner_enabled[RW]
timestamp_enabled[RW]
timestamp_error_message[W]
timestamp_threshold[RW]
visual_honeypots[RW]
Public Class Methods
css_strategy()
click to toggle source
# File lib/invisible_captcha.rb, line 73 def css_strategy [ "display:none;", "position:absolute!important;top:-9999px;left:-9999px;", "position:absolute!important;height:1px;width:1px;overflow:hidden;" ].sample end
encode(value)
click to toggle source
# File lib/invisible_captcha.rb, line 81 def encode(value) Digest::MD5.hexdigest("#{self.secret}-#{value}") end
generate_random_honeypot()
click to toggle source
# File lib/invisible_captcha.rb, line 65 def generate_random_honeypot "abcdefghijkl-mnopqrstuvwxyz".chars.sample(rand(10..20)).join end
get_honeypot()
click to toggle source
# File lib/invisible_captcha.rb, line 69 def get_honeypot honeypots.sample end
init!()
click to toggle source
# File lib/invisible_captcha.rb, line 22 def init! # Default sentence for real users if text field was visible self.sentence_for_humans = -> { I18n.t('invisible_captcha.sentence_for_humans', default: 'If you are a human, ignore this field') } # Timestamp check enabled by default self.timestamp_enabled = true # Fastest time (in seconds) to expect a human to submit the form self.timestamp_threshold = 4 # Default error message for validator when form submitted too quickly self.timestamp_error_message = -> { I18n.t('invisible_captcha.timestamp_error_message', default: 'Sorry, that was too quick! Please resubmit.') } # Make honeypots visibles self.visual_honeypots = false # If enabled, you should call anywhere in your layout the following helper, to inject the honeypot styles: # <%= invisible_captcha_styles %> self.injectable_styles = false # Spinner check enabled by default self.spinner_enabled = true # A secret key to encode some internal values self.secret = ENV['INVISIBLE_CAPTCHA_SECRET'] || SecureRandom.hex(64) end
sentence_for_humans()
click to toggle source
# File lib/invisible_captcha.rb, line 49 def sentence_for_humans call_lambda_or_return(@sentence_for_humans) end
setup() { |self| ... }
click to toggle source
# File lib/invisible_captcha.rb, line 57 def setup yield(self) if block_given? end
timestamp_error_message()
click to toggle source
# File lib/invisible_captcha.rb, line 53 def timestamp_error_message call_lambda_or_return(@timestamp_error_message) end
Private Class Methods
call_lambda_or_return(obj)
click to toggle source
# File lib/invisible_captcha.rb, line 87 def call_lambda_or_return(obj) obj.respond_to?(:call) ? obj.call : obj end