invisible_captcha 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Invisible Captcha
2
- Simple spam protection for Rails applications using honeypot strategy and for better user experience. Support for ActiveRecord (and ActiveModel) forms and for non-RESTful resources.
2
+ Simple and flexible spam protection solution for Rails applications using honeypot strategy and for better user experience.
3
+ Support for ActiveRecord (and ActiveModel) forms and for non-RESTful resources.
3
4
 
4
5
  ## Installation
5
6
  Add this line to you Gemfile:
@@ -8,69 +9,85 @@ Add this line to you Gemfile:
8
9
  gem 'invisible_captcha'
9
10
  ```
10
11
 
11
- Or install gem:
12
+ Or install gem manually:
12
13
 
13
14
  ```
14
15
  gem install invisible_captcha
15
16
  ```
16
17
 
17
18
  ## Usage
19
+ There are different ways to implement:
18
20
 
19
21
  ### Model style
20
22
  View code:
21
23
 
22
24
  ```erb
23
25
  <%= form_for(@topic) do |f| %>
24
-
25
- <!-- You can use form helper -->
26
26
  <%= f.invisible_captcha :subtitle %>
27
-
28
- <!-- or view helper -->
29
- <%= invisible_captcha :topic, :subtitle %>
30
-
31
27
  <% end %>
32
28
  ```
33
29
 
34
30
  Model code:
35
31
 
36
32
  ```ruby
37
- validates :subtitle, :invisible_captcha => true
33
+ class Topic < ActiveRecord::Base
34
+ attr_accessor :subtitle # virtual attribute, the honeypot
35
+ validates :subtitle, :invisible_captcha => true
36
+ end
37
+ ```
38
+
39
+ If you are using [strong_parameters](https://github.com/rails/strong_parameters), don't forget to keep the honeypot attribute into the params hash:
40
+ ```ruby
41
+ def topic_params
42
+ params.require(:topic).permit(:subtitle)
43
+ end
38
44
  ```
39
45
 
40
46
  ### Controller style
41
47
  View code:
42
48
 
43
49
  ```erb
44
- <%= form_tag(search_path) do %>
45
-
50
+ <%= form_for(@topic) do |f| %>
46
51
  <%= invisible_captcha %>
47
-
48
52
  <% end %>
49
53
  ```
50
54
 
51
55
  Controller code:
52
56
 
53
57
  ```ruby
54
- before_filter :check_invisible_captcha, :only => [:create, :update]
58
+ class TopicsController < ApplicationController
59
+ before_filter :check_invisible_captcha # :only => [:create, :update]
60
+ # your controller code
61
+ end
55
62
  ```
56
63
 
57
- This filter returns a response that has no content (only headers). If you desire a different behaviour, this lib provides a method to check manualy if invisible captcha (fake field) is present:
64
+ This filter triggers when the spam is the in params and responds without content (only headers). If you desire a different behaviour, you can use a provided method to check manualy if invisible captcha (fake field) is present:
58
65
 
59
66
  ```ruby
60
67
  if invisible_captcha?
61
- # invalid
68
+ # spam present
62
69
  else
63
- # valid
70
+ # no spam
64
71
  end
65
72
  ```
66
73
 
67
- If you want to use it in this way but using RESTful forms with `form_for`, you can call this method with the fake field as a parameters:
74
+ ### Controller style (resource oriented):
68
75
 
69
- ```ruby
70
- if invisible_captcha?(:topic, :subtitle)
71
- # invalid
72
- else
73
- # valid
76
+ In your form:
77
+ ```
78
+ <%= form_for(@topic) do |f| %>
79
+ <%= f.invisible_captcha :subtitle %>
80
+ <% end %>
81
+ ```
82
+
83
+ In your controller:
84
+ ```
85
+ def create
86
+ if invisible_captcha?(:topic, :subtitle)
87
+ head 200 # or redirect_to new_topic_path
88
+ else
89
+ # regular workflow
90
+ end
74
91
  end
75
92
  ```
76
93
 
@@ -79,9 +96,9 @@ If you want to customize some defaults, add the following to an initializer (con
79
96
 
80
97
  ```
81
98
  InvisibleCaptcha.setup do |ic|
82
- ic.sentence_for_humans = 'Another sentence'
83
- ic.error_message = 'Another error message'
84
- ic.fake_fields << 'fake_field'
99
+ ic.sentence_for_humans = 'If you are a human, ignore this field'
100
+ ic.error_message = 'You are a robot!'
101
+ ic.fake_fields << 'another_fake_field'
85
102
  end
86
103
  ```
87
104
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "invisible_captcha"
8
- s.version = "0.6.2"
8
+ s.version = "0.6.4"
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-10-02"
12
+ s.date = "2013-11-21"
13
13
  s.description = "Simple spam protection for Rails applications using honeypot strategy for better user experience."
14
14
  s.email = "srmarc.ai@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -22,7 +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
+ "lib/invisible_captcha/controller_methods.rb",
26
26
  "lib/invisible_captcha/form_helpers.rb",
27
27
  "lib/invisible_captcha/validator.rb",
28
28
  "lib/invisible_captcha/view_helpers.rb"
@@ -1,4 +1,4 @@
1
- require 'invisible_captcha/controller_helpers.rb'
1
+ require 'invisible_captcha/controller_methods.rb'
2
2
  require 'invisible_captcha/view_helpers.rb'
3
3
  require 'invisible_captcha/form_helpers.rb'
4
4
  require 'invisible_captcha/validator.rb'
@@ -19,7 +19,7 @@ module InvisibleCaptcha
19
19
  # InvisibleCaptcha.setup do |ic|
20
20
  # ic.sentence_for_humans = 'Another sentence'
21
21
  # ic.error_message = 'Another error message'
22
- # ic.fake_fields << 'fake_field'
22
+ # ic.fake_fields << 'another_fake_field'
23
23
  # end
24
24
  def self.setup
25
25
  yield(self)
@@ -1,5 +1,5 @@
1
1
  module InvisibleCaptcha
2
- module ControllerHelpers
2
+ module ControllerMethods
3
3
 
4
4
  def check_invisible_captcha
5
5
  head 200 if invisible_captcha?
@@ -18,4 +18,4 @@ module InvisibleCaptcha
18
18
  end
19
19
  end
20
20
 
21
- ActionController::Base.send :include, InvisibleCaptcha::ControllerHelpers
21
+ ActionController::Base.send :include, InvisibleCaptcha::ControllerMethods
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.6.2
4
+ version: 0.6.4
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-10-02 00:00:00.000000000 Z
12
+ date: 2013-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -89,7 +89,7 @@ files:
89
89
  - VERSION
90
90
  - invisible_captcha.gemspec
91
91
  - lib/invisible_captcha.rb
92
- - lib/invisible_captcha/controller_helpers.rb
92
+ - lib/invisible_captcha/controller_methods.rb
93
93
  - lib/invisible_captcha/form_helpers.rb
94
94
  - lib/invisible_captcha/validator.rb
95
95
  - lib/invisible_captcha/view_helpers.rb
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: 1304051618189671970
111
+ hash: -428601357
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements: