Module: InvisibleCaptcha
- Defined in:
- lib/invisible_captcha.rb,
lib/invisible_captcha/railtie.rb,
lib/invisible_captcha/version.rb,
lib/invisible_captcha/form_helpers.rb,
lib/invisible_captcha/view_helpers.rb,
lib/invisible_captcha/controller_ext.rb
Defined Under Namespace
Modules: ControllerExt, FormHelpers, ViewHelpers Classes: Railtie
Constant Summary collapse
- VERSION =
"2.0.0"
Class Attribute Summary collapse
-
.honeypots ⇒ Object
Returns the value of attribute honeypots.
-
.injectable_styles ⇒ Object
Returns the value of attribute injectable_styles.
-
.secret ⇒ Object
Returns the value of attribute secret.
- .sentence_for_humans ⇒ Object
-
.spinner_enabled ⇒ Object
Returns the value of attribute spinner_enabled.
-
.timestamp_enabled ⇒ Object
Returns the value of attribute timestamp_enabled.
- .timestamp_error_message ⇒ Object
-
.timestamp_threshold ⇒ Object
Returns the value of attribute timestamp_threshold.
-
.visual_honeypots ⇒ Object
Returns the value of attribute visual_honeypots.
Class Method Summary collapse
- .css_strategy ⇒ Object
- .encode(value) ⇒ Object
- .generate_random_honeypot ⇒ Object
- .get_honeypot ⇒ Object
- .init! ⇒ Object
- .setup {|_self| ... } ⇒ Object
Class Attribute Details
.honeypots ⇒ Object
Returns the value of attribute honeypots.
14 15 16 |
# File 'lib/invisible_captcha.rb', line 14 def honeypots @honeypots end |
.injectable_styles ⇒ Object
Returns the value of attribute injectable_styles.
14 15 16 |
# File 'lib/invisible_captcha.rb', line 14 def injectable_styles @injectable_styles end |
.secret ⇒ Object
Returns the value of attribute secret.
14 15 16 |
# File 'lib/invisible_captcha.rb', line 14 def secret @secret end |
.sentence_for_humans ⇒ Object
49 50 51 |
# File 'lib/invisible_captcha.rb', line 49 def sentence_for_humans call_lambda_or_return(@sentence_for_humans) end |
.spinner_enabled ⇒ Object
Returns the value of attribute spinner_enabled.
14 15 16 |
# File 'lib/invisible_captcha.rb', line 14 def spinner_enabled @spinner_enabled end |
.timestamp_enabled ⇒ Object
Returns the value of attribute timestamp_enabled.
14 15 16 |
# File 'lib/invisible_captcha.rb', line 14 def @timestamp_enabled end |
.timestamp_error_message ⇒ Object
53 54 55 |
# File 'lib/invisible_captcha.rb', line 53 def call_lambda_or_return(@timestamp_error_message) end |
.timestamp_threshold ⇒ Object
Returns the value of attribute timestamp_threshold.
14 15 16 |
# File 'lib/invisible_captcha.rb', line 14 def @timestamp_threshold end |
.visual_honeypots ⇒ Object
Returns the value of attribute visual_honeypots.
14 15 16 |
# File 'lib/invisible_captcha.rb', line 14 def visual_honeypots @visual_honeypots end |
Class Method Details
.css_strategy ⇒ Object
73 74 75 76 77 78 79 |
# 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) ⇒ Object
81 82 83 |
# File 'lib/invisible_captcha.rb', line 81 def encode(value) Digest::MD5.hexdigest("#{self.secret}-#{value}") end |
.generate_random_honeypot ⇒ Object
65 66 67 |
# File 'lib/invisible_captcha.rb', line 65 def generate_random_honeypot "abcdefghijkl-mnopqrstuvwxyz".chars.sample(rand(10..20)).join end |
.get_honeypot ⇒ Object
69 70 71 |
# File 'lib/invisible_captcha.rb', line 69 def get_honeypot honeypots.sample end |
.init! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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. = true # Fastest time (in seconds) to expect a human to submit the form self. = 4 # Default error message for validator when form submitted too quickly self. = -> { 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 |
.setup {|_self| ... } ⇒ Object
57 58 59 |
# File 'lib/invisible_captcha.rb', line 57 def setup yield(self) if block_given? end |