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 =
"0.12.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.honeypotsObject

Returns the value of attribute honeypots.



12
13
14
# File 'lib/invisible_captcha.rb', line 12

def honeypots
  @honeypots
end

.injectable_stylesObject

Returns the value of attribute injectable_styles.



12
13
14
# File 'lib/invisible_captcha.rb', line 12

def injectable_styles
  @injectable_styles
end

.sentence_for_humansObject



39
40
41
# File 'lib/invisible_captcha.rb', line 39

def sentence_for_humans
  call_lambda_or_return(@sentence_for_humans)
end

.timestamp_enabledObject

Returns the value of attribute timestamp_enabled.



12
13
14
# File 'lib/invisible_captcha.rb', line 12

def timestamp_enabled
  @timestamp_enabled
end

.timestamp_error_messageObject



43
44
45
# File 'lib/invisible_captcha.rb', line 43

def timestamp_error_message
  call_lambda_or_return(@timestamp_error_message)
end

.timestamp_thresholdObject

Returns the value of attribute timestamp_threshold.



12
13
14
# File 'lib/invisible_captcha.rb', line 12

def timestamp_threshold
  @timestamp_threshold
end

.visual_honeypotsObject

Returns the value of attribute visual_honeypots.



12
13
14
# File 'lib/invisible_captcha.rb', line 12

def visual_honeypots
  @visual_honeypots
end

Class Method Details

.css_strategyObject



63
64
65
66
67
68
69
# File 'lib/invisible_captcha.rb', line 63

def css_strategy
  [
    "display:none;",
    "position:absolute!important;top:-9999px;left:-9999px;",
    "position:absolute!important;height:1px;width:1px;overflow:hidden;"
  ].sample
end

.generate_random_honeypotObject



55
56
57
# File 'lib/invisible_captcha.rb', line 55

def generate_random_honeypot
  "abcdefghijkl-mnopqrstuvwxyz".chars.sample(rand(10..20)).join
end

.get_honeypotObject



59
60
61
# File 'lib/invisible_captcha.rb', line 59

def get_honeypot
  honeypots.sample
end

.init!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/invisible_captcha.rb', line 18

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 of your layout the following helper, to inject the honeypot styles:
  #  <%= invisible_captcha_styles %>
  self.injectable_styles = false
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



47
48
49
# File 'lib/invisible_captcha.rb', line 47

def setup
  yield(self) if block_given?
end