humanizer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/LICENSE +20 -0
- data/README.md +31 -0
- data/ROADMAP.md +1 -0
- data/lib/generators/humanizer_generator.rb +26 -0
- data/lib/generators/templates/create_humanizer_questions.rb +37 -0
- data/lib/generators/templates/en.yml +4 -0
- data/lib/humanizer.rb +33 -0
- data/lib/humanizer/version.rb +3 -0
- data/lib/humanizer_question.rb +4 -0
- metadata +74 -0
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Antti Akonniemi, Kisko Labs
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Humanizer is a very simple CAPTCHA method. It has a table with questions and answers which is used to validate that the user is an actual human. Currently only Mysql an Sqlite3 are supported. Tested only on Rails 3.
|
2
|
+
|
3
|
+
### Installation
|
4
|
+
|
5
|
+
1. gem install humanizer
|
6
|
+
2. rails g humanizer
|
7
|
+
3. rake db:migrate
|
8
|
+
|
9
|
+
### Usage
|
10
|
+
|
11
|
+
1. In your model add require_human_on method, example:
|
12
|
+
|
13
|
+
class User < ActiveRecord::Base
|
14
|
+
require_human_on :create
|
15
|
+
end
|
16
|
+
|
17
|
+
2. Ask the question in the form, example:
|
18
|
+
|
19
|
+
<%= f.label :humanizer_question_answer, HumanizerQuestion.find(@user.humanizer_question_id).question, :class => "required" %>
|
20
|
+
<%= f.text_field :humanizer_question_answer %>
|
21
|
+
<%= f.hidden_field :humanizer_question_id, :value => @user.humanizer_question_id %>
|
22
|
+
|
23
|
+
### Configuration
|
24
|
+
|
25
|
+
Default translations can be found from config/locales/humanizer.en.yml
|
26
|
+
|
27
|
+
You might want to add / change question and answer pairs. This can be easily done by adding / modifying entries in HumanizerQuestion model
|
28
|
+
|
29
|
+
### Live sites
|
30
|
+
|
31
|
+
* [ArcticStartup.com](http://arcticstartup.com/) - signup form
|
data/ROADMAP.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class HumanizerGenerator < Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
|
4
|
+
LOCALE_FILE = File.join(File.dirname(__FILE__) , "templates", "en.yml")
|
5
|
+
MIGRATIONS_FILE = File.join(File.dirname(__FILE__) , "templates", "create_humanizer_questions.rb")
|
6
|
+
|
7
|
+
def add_my_initializer
|
8
|
+
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
|
+
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
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'humanizer_question'
|
2
|
+
module Humanizer
|
3
|
+
|
4
|
+
def require_human_on(validate_on)
|
5
|
+
class_eval do
|
6
|
+
validate :humanizer_answer, :on => validate_on
|
7
|
+
attr_accessor :humanizer_question_answer, :humanizer_question_id
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
super
|
11
|
+
case ActiveRecord::Base.connection.adapter_name
|
12
|
+
when 'MySQL'
|
13
|
+
random_sql='rand()'
|
14
|
+
when 'SQLite'
|
15
|
+
random_sql='random()'
|
16
|
+
end
|
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
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveRecord::Base.extend Humanizer
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: humanizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Antti Akonniemi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-27 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Recaptcha was too much for us, so we created this. Shout-out to brain_busters
|
22
|
+
email:
|
23
|
+
- antti@kiskolabs.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/generators/humanizer_generator.rb
|
32
|
+
- lib/generators/templates/create_humanizer_questions.rb
|
33
|
+
- lib/humanizer/version.rb
|
34
|
+
- lib/humanizer.rb
|
35
|
+
- lib/humanizer_question.rb
|
36
|
+
- LICENSE
|
37
|
+
- CHANGELOG.md
|
38
|
+
- README.md
|
39
|
+
- ROADMAP.md
|
40
|
+
- lib/generators/templates/en.yml
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/kiskolabs/humanizer
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 3
|
64
|
+
- 6
|
65
|
+
version: 1.3.6
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: humanizer
|
69
|
+
rubygems_version: 1.3.6
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: A really simple captcha solution
|
73
|
+
test_files: []
|
74
|
+
|