invisible_captcha 0.5.0 → 0.6.0
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 +39 -8
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/invisible_captcha.gemspec +3 -3
- data/lib/invisible_captcha.rb +16 -5
- data/lib/invisible_captcha/controller_helpers.rb +11 -1
- data/lib/invisible_captcha/validator.rb +2 -2
- metadata +5 -4
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Invisible Captcha
|
2
|
-
Simple spam protection for Rails applications using honeypot strategy. Support for
|
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.
|
3
3
|
|
4
4
|
## Installation
|
5
5
|
Add this line to you Gemfile:
|
@@ -16,8 +16,8 @@ gem install invisible_captcha
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
###
|
20
|
-
|
19
|
+
### Model style
|
20
|
+
View code:
|
21
21
|
|
22
22
|
```erb
|
23
23
|
<%= form_for(@topic) do |f| %>
|
@@ -31,14 +31,14 @@ In your form:
|
|
31
31
|
<% end %>
|
32
32
|
```
|
33
33
|
|
34
|
-
|
34
|
+
Model code:
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
validates :subtitle, :invisible_captcha => true
|
38
38
|
```
|
39
39
|
|
40
|
-
###
|
41
|
-
|
40
|
+
### Controller style
|
41
|
+
View code:
|
42
42
|
|
43
43
|
```erb
|
44
44
|
<%= form_tag(search_path) do %>
|
@@ -48,10 +48,41 @@ In your form:
|
|
48
48
|
<% end %>
|
49
49
|
```
|
50
50
|
|
51
|
-
|
51
|
+
Controller code:
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
before_filter :check_invisible_captcha
|
54
|
+
before_filter :check_invisible_captcha, :only => [:create, :update]
|
55
|
+
```
|
56
|
+
|
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:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
if invisible_captcha?
|
61
|
+
# invalid
|
62
|
+
else
|
63
|
+
# valid
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
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:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
if invisible_captcha?(:topic, :subtitle)
|
71
|
+
# invalid
|
72
|
+
else
|
73
|
+
# valid
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
### Setup
|
78
|
+
If you want to customize some defaults, add the following to an initializer (config/initializers/invisible_captcha.rb):
|
79
|
+
|
80
|
+
```
|
81
|
+
InvisibleCaptcha.setup do |ic|
|
82
|
+
ic.sentence_for_humans = 'Another sentence'
|
83
|
+
ic.error_message = 'Another error message'
|
84
|
+
ic.fake_fields << 'fake_field'
|
85
|
+
end
|
55
86
|
```
|
56
87
|
|
57
88
|
## 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 spam protection for Rails applications using honeypot strategy.}
|
20
|
+
gem.description = %Q{Simple spam protection for Rails applications using honeypot strategy for better user experience.}
|
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.
|
1
|
+
0.6.0
|
data/invisible_captcha.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "invisible_captcha"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.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-09-
|
13
|
-
s.description = "Simple spam protection for Rails applications using honeypot strategy."
|
12
|
+
s.date = "2013-09-03"
|
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 = [
|
16
16
|
"README.md"
|
data/lib/invisible_captcha.rb
CHANGED
@@ -5,17 +5,28 @@ require "#{GEM_PATH}/form_helpers.rb"
|
|
5
5
|
require "#{GEM_PATH}/validator.rb"
|
6
6
|
|
7
7
|
module InvisibleCaptcha
|
8
|
-
|
9
8
|
# Default sentence for humans if text field is visible
|
10
9
|
mattr_accessor :sentence_for_humans
|
11
10
|
self.sentence_for_humans = 'If you are a human, ignore this field'
|
12
11
|
|
13
12
|
# Default error message for validator
|
14
13
|
mattr_accessor :error_message
|
15
|
-
self.error_message = '
|
14
|
+
self.error_message = 'You are a robot!'
|
15
|
+
|
16
|
+
# Default fake fields for controller based workflow
|
17
|
+
mattr_accessor :fake_fields
|
18
|
+
self.fake_fields = ['foo_id', 'bar_id', 'baz_id']
|
16
19
|
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
+
# InvisibleCaptcha.setup do |ic|
|
21
|
+
# ic.sentence_for_humans = 'Another sentence'
|
22
|
+
# ic.error_message = 'Another error message'
|
23
|
+
# ic.fake_fields << 'fake_field'
|
24
|
+
# end
|
25
|
+
def self.setup
|
26
|
+
yield(self)
|
27
|
+
end
|
20
28
|
|
29
|
+
def self.fake_field
|
30
|
+
self.fake_fields.sample
|
31
|
+
end
|
21
32
|
end
|
@@ -2,9 +2,19 @@ module InvisibleCaptcha
|
|
2
2
|
module ControllerHelpers
|
3
3
|
|
4
4
|
def check_invisible_captcha
|
5
|
-
head 200 if
|
5
|
+
head 200 if invisible_captcha?
|
6
6
|
end
|
7
7
|
|
8
|
+
def invisible_captcha?(fake_resource = nil, fake_field = nil)
|
9
|
+
if fake_resource && fake_field
|
10
|
+
return true if params[fake_resource][fake_field].present?
|
11
|
+
else
|
12
|
+
InvisibleCaptcha.fake_fields.each do |field|
|
13
|
+
return true if params[field].present?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
false
|
17
|
+
end
|
8
18
|
end
|
9
19
|
end
|
10
20
|
|
@@ -4,7 +4,7 @@ module InvisibleCaptcha
|
|
4
4
|
class InvisibleCaptchaValidator < ActiveModel::EachValidator
|
5
5
|
|
6
6
|
def validate_each(record, attribute, value)
|
7
|
-
if
|
7
|
+
if invisible_captcha?(record, attribute)
|
8
8
|
record.errors.clear
|
9
9
|
record.errors[:base] = InvisibleCaptcha.error_message
|
10
10
|
end
|
@@ -12,7 +12,7 @@ module InvisibleCaptcha
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def
|
15
|
+
def invisible_captcha?(object, attribute)
|
16
16
|
object.send(attribute).present?
|
17
17
|
end
|
18
18
|
|
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
|
+
version: 0.6.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-09-
|
12
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -75,7 +75,8 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
description: Simple spam protection for Rails applications using honeypot strategy
|
78
|
+
description: Simple spam protection for Rails applications using honeypot strategy
|
79
|
+
for better user experience.
|
79
80
|
email: srmarc.ai@gmail.com
|
80
81
|
executables: []
|
81
82
|
extensions: []
|
@@ -107,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
108
|
version: '0'
|
108
109
|
segments:
|
109
110
|
- 0
|
110
|
-
hash:
|
111
|
+
hash: 260613869
|
111
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
113
|
none: false
|
113
114
|
requirements:
|