Module: InvisibleCaptcha::ControllerExt

Defined in:
lib/invisible_captcha/controller_ext.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#default_on_spamObject



25
26
27
# File 'lib/invisible_captcha/controller_ext.rb', line 25

def default_on_spam
  head(200)
end

#detect_spam(options = {}) ⇒ Object



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

def detect_spam(options = {})
  if invisible_captcha?(options)
    on_spam_action(options)
  end
end

#invisible_captcha?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/invisible_captcha/controller_ext.rb', line 29

def invisible_captcha?(options = {})
  honeypot = options[:honeypot]
  scope    = options[:scope] || controller_name.singularize

  if honeypot
    # If honeypot is presented, search for:
    # - honeypot: params[:subtitle]
    # - honeypot with scope: params[:topic][:subtitle]
    if params[honeypot].present? || (params[scope] && params[scope][honeypot].present?)
      return true
    end
  else
    InvisibleCaptcha.honeypots.each do |field|
      return true if params[field].present?
    end
  end
  false
end

#on_spam_action(options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/invisible_captcha/controller_ext.rb', line 17

def on_spam_action(options = {})
  if action = options[:on_spam]
    send(action)
  else
    default_on_spam
  end
end