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.9.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.error_messageObject



41
42
43
# File 'lib/invisible_captcha.rb', line 41

def error_message
  call_lambda_or_return(@error_message)
end

.honeypotsObject

Returns the value of attribute honeypots.



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

def honeypots
  @honeypots
end

.sentence_for_humansObject



37
38
39
# File 'lib/invisible_captcha.rb', line 37

def sentence_for_humans
  call_lambda_or_return(@sentence_for_humans)
end

.timestamp_error_messageObject



45
46
47
# File 'lib/invisible_captcha.rb', line 45

def timestamp_error_message
  call_lambda_or_return(@timestamp_error_message)
end

.timestamp_thresholdObject

Returns the value of attribute timestamp_threshold.



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

def timestamp_threshold
  @timestamp_threshold
end

.visual_honeypotsObject

Returns the value of attribute visual_honeypots.



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

def visual_honeypots
  @visual_honeypots
end

Class Method Details

.get_honeypotObject



53
54
55
# File 'lib/invisible_captcha.rb', line 53

def get_honeypot
  honeypots.sample
end

.init!Object



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

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') }

  # Default error message for validator
  self.error_message = -> { I18n.t('invisible_captcha.error_message', default: 'You are a robot!') }

  # Default fake fields for controller based workflow
  self.honeypots = ['foo_id', 'bar_id', 'baz_id']

  # 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
end

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

Yields:

  • (_self)

Yield Parameters:



49
50
51
# File 'lib/invisible_captcha.rb', line 49

def setup
  yield(self) if block_given?
end