invisible_captcha 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Invisible Captcha
2
- Simple protection for ActiveModel (and ActiveRecord) instances using honeypot strategy.
2
+ Simple spam protection for Rails applications using honeypot strategy. Support for ActiveModel (and ActiveRecord) forms and for non-RESTful resources.
3
3
 
4
4
  ## Installation
5
5
  Add this line to you Gemfile:
@@ -15,9 +15,11 @@ gem install invisible_captcha
15
15
  ```
16
16
 
17
17
  ## Usage
18
+
19
+ ### RESTful style
18
20
  In your form:
19
21
 
20
- ```ruby
22
+ ```erb
21
23
  <%= form_for(@topic) do |f| %>
22
24
 
23
25
  <!-- You can use form helper -->
@@ -29,11 +31,28 @@ In your form:
29
31
  <% end %>
30
32
  ```
31
33
 
32
- In your ActiveModel:
34
+ In your model:
33
35
 
34
36
  ```ruby
35
37
  validates :subtitle, :invisible_captcha => true
36
38
  ```
37
39
 
40
+ ### Non-RESTful style
41
+ In your form:
42
+
43
+ ```erb
44
+ <%= form_tag(search_path) do %>
45
+
46
+ <%= invisible_captcha %>
47
+
48
+ <% end %>
49
+ ```
50
+
51
+ In your controller:
52
+
53
+ ```ruby
54
+ before_filter :check_invisible_captcha
55
+ ```
56
+
38
57
  ## License
39
58
  Copyright (c) 2012 Marc Anguera. Invisible Captcha is released under the [MIT](http://opensource.org/licenses/MIT) License.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.homepage = "http://github.com/markets/invisible_captcha"
18
18
  gem.license = "MIT"
19
19
  gem.summary = %Q{Simple honeypot protection for RoR apps}
20
- gem.description = %Q{Simple protection for ActiveModel (and ActiveRecord) instances using honeypot strategy.}
20
+ gem.description = %Q{Simple spam protection for Rails applications using honeypot strategy.}
21
21
  gem.email = "srmarc.ai@gmail.com"
22
22
  gem.authors = ["Marc Anguera Insa"]
23
23
  # dependencies defined in Gemfile
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "invisible_captcha"
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marc Anguera Insa"]
12
- s.date = "2013-08-29"
13
- s.description = "Simple protection for ActiveModel (and ActiveRecord) instances using honeypot strategy."
12
+ s.date = "2013-09-02"
13
+ s.description = "Simple spam protection for Rails applications using honeypot strategy."
14
14
  s.email = "srmarc.ai@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "README.md"
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  "VERSION",
23
23
  "invisible_captcha.gemspec",
24
24
  "lib/invisible_captcha.rb",
25
+ "lib/invisible_captcha/controller_helpers.rb",
25
26
  "lib/invisible_captcha/form_helpers.rb",
26
27
  "lib/invisible_captcha/validator.rb",
27
28
  "lib/invisible_captcha/view_helpers.rb"
@@ -1,14 +1,21 @@
1
1
  GEM_PATH = File.dirname(__FILE__) + "/invisible_captcha"
2
+ require "#{GEM_PATH}/controller_helpers.rb"
2
3
  require "#{GEM_PATH}/view_helpers.rb"
3
4
  require "#{GEM_PATH}/form_helpers.rb"
4
5
  require "#{GEM_PATH}/validator.rb"
5
6
 
6
7
  module InvisibleCaptcha
7
8
 
9
+ # Default sentence for humans if text field is visible
8
10
  mattr_accessor :sentence_for_humans
9
11
  self.sentence_for_humans = 'If you are a human, ignore this field'
10
12
 
13
+ # Default error message for validator
11
14
  mattr_accessor :error_message
12
15
  self.error_message = 'YOU ARE A ROBOT!'
13
16
 
17
+ # Default fake field name for text_field_tag
18
+ mattr_accessor :fake_field
19
+ self.fake_field = :query
20
+
14
21
  end
@@ -0,0 +1,11 @@
1
+ module InvisibleCaptcha
2
+ module ControllerHelpers
3
+
4
+ def check_invisible_captcha
5
+ head 200 if params[InvisibleCaptcha.fake_field].present?
6
+ end
7
+
8
+ end
9
+ end
10
+
11
+ ActionController::Base.send :include, InvisibleCaptcha::ControllerHelpers
@@ -1,28 +1,49 @@
1
1
  module InvisibleCaptcha
2
2
  module ViewHelpers
3
3
 
4
- def invisible_captcha(model_name, method)
5
- build_invisible_captcha(model_name.to_s, method.to_s)
4
+ def invisible_captcha(resource = nil, method = nil)
5
+ build_invisible_captcha(resource, method)
6
6
  end
7
7
 
8
8
  private
9
9
 
10
- def build_invisible_captcha(model_name, method)
10
+ def build_invisible_captcha(resource = nil, method = nil)
11
+ resource = resource ? resource.to_s : InvisibleCaptcha.fake_field
11
12
  label = InvisibleCaptcha.sentence_for_humans
12
- html_id = "#{model_name}_#{Time.now.to_i}"
13
+ html_id = generate_html_id(resource)
13
14
 
14
15
  content_tag(:div, :id => html_id) do
15
- insert_inline_css_for(html_id) +
16
- label_tag("#{model_name}_#{method}", label) +
17
- text_field_tag("#{model_name}[#{method}]")
16
+ insert_inline_css(html_id) +
17
+ label_tag(build_label_name(resource, method), label) +
18
+ text_field_tag(build_text_field_name(resource, method))
18
19
  end.html_safe
19
20
  end
20
21
 
21
- def insert_inline_css_for(container_id)
22
+ def generate_html_id(resource)
23
+ "#{resource}_#{Time.now.to_i}"
24
+ end
25
+
26
+ def insert_inline_css(container_id)
22
27
  content_tag(:style, :type => 'text/css', :media => 'screen', :scoped => 'scoped') do
23
28
  "##{container_id} { display:none; }"
24
29
  end
25
30
  end
31
+
32
+ def build_label_name(resource, method = nil)
33
+ if method.present?
34
+ "#{resource}_#{method}"
35
+ else
36
+ resource
37
+ end
38
+ end
39
+
40
+ def build_text_field_name(resource, method = nil)
41
+ if method.present?
42
+ "#{resource}[#{method}]"
43
+ else
44
+ resource
45
+ end
46
+ end
26
47
  end
27
48
  end
28
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invisible_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-29 00:00:00.000000000 Z
12
+ date: 2013-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -75,8 +75,7 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
- description: Simple protection for ActiveModel (and ActiveRecord) instances using
79
- honeypot strategy.
78
+ description: Simple spam protection for Rails applications using honeypot strategy.
80
79
  email: srmarc.ai@gmail.com
81
80
  executables: []
82
81
  extensions: []
@@ -89,6 +88,7 @@ files:
89
88
  - VERSION
90
89
  - invisible_captcha.gemspec
91
90
  - lib/invisible_captcha.rb
91
+ - lib/invisible_captcha/controller_helpers.rb
92
92
  - lib/invisible_captcha/form_helpers.rb
93
93
  - lib/invisible_captcha/validator.rb
94
94
  - lib/invisible_captcha/view_helpers.rb
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: 403370753
110
+ hash: -400465203
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  none: false
113
113
  requirements: