humanizer 1.0.0 → 2.0.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/CHANGELOG.md +10 -2
- data/LICENSE +1 -1
- data/README.md +7 -7
- data/lib/generators/humanizer_generator.rb +2 -21
- data/lib/generators/templates/en.yml +40 -1
- data/lib/humanizer.rb +40 -28
- data/lib/humanizer/version.rb +1 -1
- metadata +8 -7
- data/ROADMAP.md +0 -1
- data/lib/generators/templates/create_humanizer_questions.rb +0 -37
- data/lib/humanizer_question.rb +0 -4
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
-
### 2010-06-
|
1
|
+
### Humanizer 2.0.0 (2010-06-30)
|
2
|
+
|
3
|
+
Rewrite.
|
4
|
+
Database and mapper agnosticism.
|
5
|
+
Use locale YAML files for storage.
|
6
|
+
|
7
|
+
|
8
|
+
### Humanizer 1.0.0 (2010-06-27)
|
2
9
|
|
3
10
|
Released to public.
|
4
11
|
|
5
|
-
|
12
|
+
|
13
|
+
### Humanizer 0.0.1 (2010-06-26)
|
6
14
|
|
7
15
|
First version created.
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
Humanizer is a very simple CAPTCHA method. It has a
|
1
|
+
Humanizer is a very simple CAPTCHA method. It has a localized YAML file with questions and answers which is used to validate that the user is an actual human. Any model that includes ActiveModel::Validations should work. Our aim is to be database and mapper agnostic, so if it doesn't work for you, open an issue. Humanizer only works with Rails 3.
|
2
2
|
|
3
3
|
### Installation
|
4
4
|
|
5
5
|
1. gem install humanizer
|
6
6
|
2. rails g humanizer
|
7
|
-
3. rake db:migrate
|
8
7
|
|
9
8
|
### Usage
|
10
9
|
|
11
|
-
1. In your model add require_human_on method, example:
|
10
|
+
1. In your model, include Humanizer and add the #require_human_on method, example:
|
12
11
|
|
13
12
|
class User < ActiveRecord::Base
|
13
|
+
include Humanizer
|
14
14
|
require_human_on :create
|
15
15
|
end
|
16
16
|
|
17
17
|
2. Ask the question in the form, example:
|
18
18
|
|
19
|
-
<%= f.label :
|
20
|
-
<%= f.text_field :
|
21
|
-
<%= f.hidden_field :humanizer_question_id
|
19
|
+
<%= f.label :humanizer_answer, @model.humanizer_question %>
|
20
|
+
<%= f.text_field :humanizer_answer %>
|
21
|
+
<%= f.hidden_field :humanizer_question_id %>
|
22
22
|
|
23
23
|
### Configuration
|
24
24
|
|
25
25
|
Default translations can be found from config/locales/humanizer.en.yml
|
26
26
|
|
27
|
-
You might want to add / change question and answer pairs. This can be easily done by adding / modifying entries in
|
27
|
+
You might want to add / change question and answer pairs. This can be easily done by adding / modifying entries in locales file.
|
28
28
|
|
29
29
|
### Live sites
|
30
30
|
|
@@ -1,26 +1,7 @@
|
|
1
|
-
class HumanizerGenerator < Rails::Generators::Base
|
2
|
-
include Rails::Generators::Migration
|
3
|
-
|
1
|
+
class HumanizerGenerator < Rails::Generators::Base
|
4
2
|
LOCALE_FILE = File.join(File.dirname(__FILE__) , "templates", "en.yml")
|
5
|
-
MIGRATIONS_FILE = File.join(File.dirname(__FILE__) , "templates", "create_humanizer_questions.rb")
|
6
3
|
|
7
|
-
def
|
4
|
+
def add_locale
|
8
5
|
template LOCALE_FILE, "config/locales/humanizer.en.yml"
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
class_option :"skip-migration", :type => :boolean, :desc => "Don't generate a migration for the humanizer questions table"
|
13
|
-
|
14
|
-
def copy_files(*args)
|
15
|
-
migration_template MIGRATIONS_FILE, "db/migrate/create_humanizer_questions.rb" unless options["skip-migration"]
|
16
6
|
end
|
17
|
-
|
18
|
-
def self.next_migration_number(dirname) #:nodoc:
|
19
|
-
if ActiveRecord::Base.timestamped_migrations
|
20
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
21
|
-
else
|
22
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
7
|
end
|
@@ -1,4 +1,43 @@
|
|
1
1
|
en:
|
2
2
|
humanizer:
|
3
3
|
validation:
|
4
|
-
error:
|
4
|
+
error: You're not a human
|
5
|
+
questions:
|
6
|
+
- question: Two plus two?
|
7
|
+
answers: ["4", "four"]
|
8
|
+
- question: Jack and Jill went up the...
|
9
|
+
answer: hill
|
10
|
+
- question: What is the number before twelve?
|
11
|
+
answers: ["11", "eleven"]
|
12
|
+
- question: Five times two is what?
|
13
|
+
answers: ["10", "ten"]
|
14
|
+
- question: "Insert the next number in this sequence: 10, 11, 12, 13, 14, .."
|
15
|
+
answers: ["15", "fifteen"]
|
16
|
+
- question: "What is five times five?"
|
17
|
+
answers: ["25", "twentyfive"]
|
18
|
+
- question: "Ten divided by two is what?"
|
19
|
+
answers: ["5", "five"]
|
20
|
+
- question: What day comes after Monday?
|
21
|
+
answer: "tuesday"
|
22
|
+
- question: What is the last month of the year?
|
23
|
+
answer: "december"
|
24
|
+
- question: How many minutes are in an hour?
|
25
|
+
answers: ["60", "sixty"]
|
26
|
+
- question: What is the opposite of down?
|
27
|
+
answer: "up"
|
28
|
+
- question: What is the opposite of north?
|
29
|
+
answer: "south"
|
30
|
+
- question: What is the opposite of bad?
|
31
|
+
answer: "good"
|
32
|
+
- question: What is 4 times four?
|
33
|
+
answers: ["16", "sixteen"]
|
34
|
+
- question: What number comes after 20?
|
35
|
+
answers: ["21", "twentyone"]
|
36
|
+
- question: What month comes before July?
|
37
|
+
answer: "june"
|
38
|
+
- question: What is fifteen divided by three?
|
39
|
+
answer: "five"
|
40
|
+
- question: What is 14 minus 4?
|
41
|
+
answers: ["10", "ten"]
|
42
|
+
- question: "What comes next? Monday, Tuesday, Wednesday.."
|
43
|
+
answer: "Thursday"
|
data/lib/humanizer.rb
CHANGED
@@ -1,33 +1,45 @@
|
|
1
|
-
require 'humanizer_question'
|
2
1
|
module Humanizer
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_accessor :humanizer_answer
|
8
|
+
attr_writer :humanizer_question_id
|
3
9
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
10
|
+
def humanizer_question
|
11
|
+
humanizer_questions[humanizer_question_id.to_i]["question"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def humanizer_question_id
|
15
|
+
@humanizer_question_id ||= Kernel.rand(humanizer_questions.count)
|
16
|
+
end
|
17
|
+
|
18
|
+
def humanizer_correct_answer?
|
19
|
+
humanizer_answer && humanizer_answers_for_id(humanizer_question_id).include?(humanizer_answer.downcase)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def humanizer_questions
|
25
|
+
@humanizer_questions ||= I18n.translate("humanizer.questions")
|
26
|
+
end
|
27
|
+
|
28
|
+
def humanizer_answers_for_id(id)
|
29
|
+
question = humanizer_questions[id.to_i]
|
30
|
+
Array(question["answer"] || question["answers"]).map { |a| a.to_s.downcase }
|
31
|
+
end
|
8
32
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
self.humanizer_question_id = HumanizerQuestion.find(:first, :order => random_sql).id if self.humanizer_question_id.nil?
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def humanizer_answer
|
22
|
-
if humanizer_question_answer.nil? or humanizer_question_answer.downcase != HumanizerQuestion.find(humanizer_question_id).answer.downcase
|
23
|
-
errors[:base] << (I18n::t("humanizer.validation.error"))
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
33
|
+
def humanizer_check_answer
|
34
|
+
errors[:base] << I18n.translate("humanizer.validation.error") unless humanizer_correct_answer?
|
35
|
+
end
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
|
39
|
+
def require_human_on(validate_on)
|
40
|
+
validate :humanizer_check_answer, :on => validate_on
|
29
41
|
end
|
30
42
|
|
31
|
-
end
|
32
|
-
|
33
|
-
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/humanizer/version.rb
CHANGED
metadata
CHANGED
@@ -3,24 +3,26 @@ name: humanizer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
-
|
6
|
+
- 2
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
version:
|
9
|
+
version: 2.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Antti Akonniemi
|
13
|
+
- Joao Carlos Cardoso
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-30 00:00:00 +03:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
21
22
|
description: Recaptcha was too much for us, so we created this. Shout-out to brain_busters
|
22
23
|
email:
|
23
24
|
- antti@kiskolabs.com
|
25
|
+
- joao@kiskolabs.com
|
24
26
|
executables: []
|
25
27
|
|
26
28
|
extensions: []
|
@@ -29,14 +31,11 @@ extra_rdoc_files: []
|
|
29
31
|
|
30
32
|
files:
|
31
33
|
- lib/generators/humanizer_generator.rb
|
32
|
-
- lib/generators/templates/create_humanizer_questions.rb
|
33
34
|
- lib/humanizer/version.rb
|
34
35
|
- lib/humanizer.rb
|
35
|
-
- lib/humanizer_question.rb
|
36
36
|
- LICENSE
|
37
37
|
- CHANGELOG.md
|
38
38
|
- README.md
|
39
|
-
- ROADMAP.md
|
40
39
|
- lib/generators/templates/en.yml
|
41
40
|
has_rdoc: true
|
42
41
|
homepage: http://github.com/kiskolabs/humanizer
|
@@ -48,6 +47,7 @@ rdoc_options: []
|
|
48
47
|
require_paths:
|
49
48
|
- lib
|
50
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
@@ -55,6 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
- 0
|
56
56
|
version: "0"
|
57
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
58
59
|
requirements:
|
59
60
|
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
@@ -66,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
67
|
requirements: []
|
67
68
|
|
68
69
|
rubyforge_project: humanizer
|
69
|
-
rubygems_version: 1.3.
|
70
|
+
rubygems_version: 1.3.7
|
70
71
|
signing_key:
|
71
72
|
specification_version: 3
|
72
73
|
summary: A really simple captcha solution
|
data/ROADMAP.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
class CreateHumanizerQuestions < ActiveRecord::Migration
|
2
|
-
|
3
|
-
def self.up
|
4
|
-
create_table :humanizer_questions, :force => true do |t|
|
5
|
-
t.column :question, :string
|
6
|
-
t.column :answer, :string
|
7
|
-
end
|
8
|
-
|
9
|
-
create "What is two plus two?", "4"
|
10
|
-
create "What is the number before twelve?", "11"
|
11
|
-
create "Five times two is what?", "10"
|
12
|
-
create "Insert the next number in this sequence: 10, 11, 12, 13, 14, ??", "15"
|
13
|
-
create "What is five times five?", "25"
|
14
|
-
create "Ten divided by two is what?", "5"
|
15
|
-
create "What day comes after Monday?", "tuesday"
|
16
|
-
create "What is the last month of the year?", "december"
|
17
|
-
create "How many minutes are in an hour?", "60"
|
18
|
-
create "What is the opposite of down?", "up"
|
19
|
-
create "What is the opposite of north?", "south"
|
20
|
-
create "What is the opposite of bad?", "good"
|
21
|
-
create "Complete the following: 'Jack and Jill went up the ???", "hill"
|
22
|
-
create "What is 4 times four?", "16"
|
23
|
-
create "What number comes after 20?", "21"
|
24
|
-
create "What month comes before July?", "june"
|
25
|
-
create "What is fifteen divided by three?", "5"
|
26
|
-
create "What is 14 minus 4?", "10"
|
27
|
-
create "What comes next? 'Monday Tuesday Wednesday ?????'", "Thursday"
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.down
|
31
|
-
drop_table :humanizer_questions
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.create(question, answer)
|
35
|
-
HumanizerQuestion.create(:question => question, :answer => answer.downcase)
|
36
|
-
end
|
37
|
-
end
|
data/lib/humanizer_question.rb
DELETED