humanizer 2.7.0 → 2.7.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +47 -3
- data/lib/humanizer/version.rb +1 -1
- data/lib/humanizer.rb +6 -8
- data/lib/humanizer_helper.rb +17 -0
- metadata +4 -4
- data/bin/rake +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df124f5def849dfe6dcfa45fc2916568e2d05a7f7250c499136cc1aa8fa27fcf
|
4
|
+
data.tar.gz: 00aded9be9984c9efd2ae3196841f27559e17b833f5fd8cd3b6de88473c451df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f1ebf7066bebe4c2abf355a8f4efb4cbf6cfc8dde621b55a59b35e5e6d037ff04cfd9b19988741755d95902be47bb7caa39c035ddf9e010e5cc92efa481cfd
|
7
|
+
data.tar.gz: 5089521d758905893cbd21a054d6b14e7247098e03d725b124801f77b12d37396541270d29aa9b7d49b8e4f0496d82e89b6aa01b1b34c1423f7c5bbd4a83ce51
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### Humanizer 2.7.1 (2024-12-19)
|
2
|
+
|
3
|
+
* Adds HumanizerHelper class for use cases when developers don't have a class they want to include Humanizer on(basic contact form for example)
|
4
|
+
|
1
5
|
### Humanizer 2.6.4 (2017-07-07)
|
2
6
|
|
3
7
|
* Prevents NoMethodError when form posts non-existing question id
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Humanizer
|
2
2
|
|
3
|
-
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 works with Rails 3
|
3
|
+
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 works with Rails 3 and 4.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add `humanizer` to your Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem
|
10
|
+
gem 'humanizer'
|
11
11
|
```
|
12
12
|
|
13
13
|
Bundle and run the generator in terminal:
|
@@ -46,6 +46,44 @@ end
|
|
46
46
|
|
47
47
|
4. If you are using strong_parameters, remember to permit `:humanizer_answer` and `:humanizer_question_id`.
|
48
48
|
|
49
|
+
## Usage without a model
|
50
|
+
|
51
|
+
Alternatively, you many use the built in HumanizerHelper class instead of using your own model (useful for something like a contact form if you don't have a model/class for this). Behavior is the same including `Humanizer` on a model, but all setters are available as optional arguments when initializing a HumanizerHelper instance.
|
52
|
+
|
53
|
+
1. Example initialization code(controller):
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
@humanizer_helper = HumanizerHelper.new
|
57
|
+
```
|
58
|
+
|
59
|
+
2. Example rails form usage:
|
60
|
+
|
61
|
+
```erb
|
62
|
+
<%= label_tag :humanizer_answer, @humanizer_helper.humanizer_question %>
|
63
|
+
<%= text_field_tag :humanizer_answer %>
|
64
|
+
<%= hidden_field_tag :humanizer_question_id, @humanizer_helper.humanizer_question_id %>
|
65
|
+
```
|
66
|
+
|
67
|
+
3. Example response handling:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
humanizer_helper = HumanizerHelper.new(humanizer_answer: params[:humanizer_answer], humanizer_question_id: params[:humanizer_question_id])
|
71
|
+
if humanizer_helper.humanizer_correct_answer?
|
72
|
+
do_stuff
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Testing
|
77
|
+
|
78
|
+
A HumanizerHelper instance provides an additional `get_correct_humanizer_answer` method to make testing easier. Example:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
question_id = find('#humanizer_question_id', visible: false).value #gets humanizer question id from example form above
|
82
|
+
humanizer_helper = HumanizerHelper.new(humanizer_question_id: question_id)
|
83
|
+
fill_in 'humanizer_answer', with: humanizer_helper.get_correct_humanizer_answer #fills in answer field from example above with the correct answer
|
84
|
+
```
|
85
|
+
|
86
|
+
|
49
87
|
## Configuration
|
50
88
|
|
51
89
|
Default translations can be found in config/locales/
|
@@ -60,7 +98,7 @@ You can just have a simple attribute on your model and use it to bypass the vali
|
|
60
98
|
|
61
99
|
```ruby
|
62
100
|
attr_accessor :bypass_humanizer
|
63
|
-
require_human_on :create, unless
|
101
|
+
require_human_on :create, :unless => :bypass_humanizer
|
64
102
|
```
|
65
103
|
|
66
104
|
Now when bypass_humanizer is true, validation will be skipped.
|
@@ -75,6 +113,11 @@ To make sure the current question doesn't get asked again, you can pass the curr
|
|
75
113
|
@user.change_humanizer_question(params[:user][:humanizer_question_id])
|
76
114
|
```
|
77
115
|
|
116
|
+
## Live sites
|
117
|
+
|
118
|
+
* [ArcticStartup.com](http://arcticstartup.com/) - sign up form
|
119
|
+
* [Paspartout](http://paspartout.com/) - sign up form
|
120
|
+
|
78
121
|
## License
|
79
122
|
|
80
123
|
Humanizer is licensed under the MIT License, for more details see the LICENSE file.
|
@@ -97,6 +140,7 @@ Humanizer is licensed under the MIT License, for more details see the LICENSE fi
|
|
97
140
|
* [seogrady](https://github.com/seogrady)
|
98
141
|
* [yairgo](https://github.com/yairgo)
|
99
142
|
* [woto](https://github.com/woto)
|
143
|
+
* [Calvin Delamere](https://github.com/elbartostrikesagain)
|
100
144
|
|
101
145
|
## CI Build Status
|
102
146
|
|
data/lib/humanizer/version.rb
CHANGED
data/lib/humanizer.rb
CHANGED
@@ -30,16 +30,14 @@ module Humanizer
|
|
30
30
|
def humanizer_questions
|
31
31
|
@humanizer_questions ||= begin
|
32
32
|
questions = I18n.translate!("humanizer.questions")
|
33
|
-
#
|
33
|
+
# Create new mutable copies of the questions with indifferent access
|
34
34
|
questions.map do |question|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
when Symbol then str = k.to_s; h[str] if h.key?(str)
|
40
|
-
end
|
35
|
+
new_hash = {}
|
36
|
+
question.each do |k, v|
|
37
|
+
new_hash[k.to_s] = v # Store everything with string keys
|
38
|
+
new_hash[k.to_sym] = v # Store everything with symbol keys
|
41
39
|
end
|
42
|
-
|
40
|
+
new_hash
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class HumanizerHelper
|
2
|
+
include ActiveModel::Validations
|
3
|
+
include Humanizer
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
options[:humanizer_question_id] = options[:humanizer_question_id].to_i unless options[:humanizer_question_id].nil?
|
7
|
+
options.each do |k, v|
|
8
|
+
self.send("#{k}=", v)
|
9
|
+
end
|
10
|
+
|
11
|
+
humanizer_question_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_correct_humanizer_answer
|
15
|
+
humanizer_answers_for_id(humanizer_question_id.to_i)[0]
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humanizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antti Akonniemi
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2024-12-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- CHANGELOG.md
|
83
83
|
- LICENSE
|
84
84
|
- README.md
|
85
|
-
- bin/rake
|
86
85
|
- lib/generators/humanizer_generator.rb
|
87
86
|
- lib/generators/templates/locales/da.yml
|
88
87
|
- lib/generators/templates/locales/de.yml
|
@@ -105,6 +104,7 @@ files:
|
|
105
104
|
- lib/generators/templates/locales/zh-TW.yml
|
106
105
|
- lib/humanizer.rb
|
107
106
|
- lib/humanizer/version.rb
|
107
|
+
- lib/humanizer_helper.rb
|
108
108
|
homepage: http://github.com/kiskolabs/humanizer
|
109
109
|
licenses:
|
110
110
|
- MIT
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: 1.3.6
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.5.16
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: A really simple captcha solution
|
data/bin/rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rake' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rake", "rake")
|