simple_captcha_reloaded 0.1.0 → 0.3.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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e5f1d37f89ed951fc718c423cd74d9e9b77cbd0
|
4
|
+
data.tar.gz: 6d04338634f0bcb29985dbd7b0fc6042402c33c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6dc2a2eeea08c9faea959ec80c031af293fb3310cb11dc2d07115e5dc345dace2adfdeedb0f6a8e43fe8f7cb6a0c81a5da772b0ec0e6d3e1284aa3576f47180
|
7
|
+
data.tar.gz: d8b180bd8ae8cd9b24028de3af4f95ae2ef1a05fe1d39c46e70fc855c34f0cf97500bc4d8bb7300b59ed9d12fd854e84f69795cd8513dffbb75e0120a8e65c6a
|
data/README.md
CHANGED
@@ -3,19 +3,21 @@
|
|
3
3
|
[](https://travis-ci.org/zealot128/simple_captcha_reloaded)
|
4
4
|
[](http://badge.fury.io/rb/simple_captcha_reloaded)
|
5
5
|
|
6
|
-
This is a rewrite of the popular Simple-Captcha Gem.
|
6
|
+
This is a rewrite of the popular Simple-Captcha Gem(s). Similarly to Simple-Captcha, it provides an easy way to integrate a Captcha into a Rails application. In comparison to the older Gem(s), I decided to drop support for ancient versions of Rails + Formtastic + Mongoid, but instead add specs, code restructuring and support for SimpleForm, with the goal, to make it even easier to use.
|
7
7
|
|
8
8
|
## Features
|
9
9
|
|
10
|
-
* Works with Rails 4.1
|
10
|
+
* Works with Rails 4.1, 4.2, Ruby 2.0+ (keyword arguments)
|
11
11
|
* Integrated into Model validation flow
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
12
|
+
* controller integration for custom flow
|
13
|
+
* Optional SimpleForm integration (v.3.0 and 3.1)
|
14
|
+
* Optional Formtastic integration (v.2.3 and 3.1)
|
15
|
+
* Uses a database table to track random captchas (pg, myqsl, sqlite tested)
|
16
|
+
* Uses Imagemagick to generate the Captcha and stream it to the client, without file access
|
15
17
|
|
16
18
|
## Prerequisites
|
17
19
|
|
18
|
-
This needs Rails (4.1+), ActiveRecord with a database (all should be fine) and
|
20
|
+
This needs Rails (4.1+), ActiveRecord with a database (all should be fine) and Imagemagick installed on the server.
|
19
21
|
|
20
22
|
Mac:
|
21
23
|
|
@@ -57,7 +59,7 @@ class Message < ActiveRecord::Base
|
|
57
59
|
end
|
58
60
|
```
|
59
61
|
|
60
|
-
this adds 2 new methods: ``valid_with_captcha?`` and ``save_with_captcha`` to the model. Use it like this in controller:
|
62
|
+
this adds 2 new methods: ``valid_with_captcha?`` and ``save_with_captcha`` to the model, as well as 2 virtual attributes captcha and captcha_key. Use it like this in controller:
|
61
63
|
|
62
64
|
```ruby
|
63
65
|
class MessagesController < ApplicationController
|
@@ -76,9 +78,9 @@ class MessagesController < ApplicationController
|
|
76
78
|
end
|
77
79
|
```
|
78
80
|
|
79
|
-
Make sure to
|
81
|
+
Make sure to whitelist the attributes ``captcha`` and ``captcha_key`` with Strong Parameters.
|
80
82
|
|
81
|
-
To show the captcha, you can use the SimpleForm helper:
|
83
|
+
To show the captcha, you can use the SimpleForm or Formtastic helper or roll a total custom field:
|
82
84
|
|
83
85
|
### Simple Form
|
84
86
|
|
@@ -90,9 +92,22 @@ The Gem provides a custom input for SimpleForm:
|
|
90
92
|
= f.submit
|
91
93
|
```
|
92
94
|
|
95
|
+
To use it, just require it manually anywhere in your code (config/application.rb or a initializer file):
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
require 'simple_captcha_reloaded/adapters/simple_form'
|
99
|
+
```
|
100
|
+
|
101
|
+
|
93
102
|
### Formtastic
|
94
103
|
|
95
|
-
|
104
|
+
The Formtastic adapter works exactly like the simple form one.
|
105
|
+
|
106
|
+
*You can't include both at the same time, as both have the same naming schema and will load each other's adapter*
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
require 'simple_captcha_reloaded/adapters/formtastic'
|
110
|
+
```
|
96
111
|
|
97
112
|
### Manual by using default Rails view helper
|
98
113
|
|
@@ -133,7 +148,7 @@ Adjust it to your needs:
|
|
133
148
|
|
134
149
|
### Manual Validation
|
135
150
|
|
136
|
-
Now you can call a method in your controller to check if the
|
151
|
+
Now you can call a method in your controller to check if the Captcha is valid:
|
137
152
|
|
138
153
|
```ruby
|
139
154
|
def submit
|
@@ -147,6 +162,8 @@ end
|
|
147
162
|
|
148
163
|
## Customizing
|
149
164
|
|
165
|
+
Translations: Just have a look at config/locales/simple_captcha.en.yml with defaults for German and English. Just overwrite the keys in your own translation file.
|
166
|
+
|
150
167
|
### Captcha Options
|
151
168
|
|
152
169
|
```ruby
|
@@ -199,3 +216,11 @@ The Gem uses **Appraisal**, to create various configuration Gem sets. For each G
|
|
199
216
|
|
200
217
|
If you need to add new controller methods to the dummy app, have a look at ``spec/template.rb``
|
201
218
|
|
219
|
+
|
220
|
+
## Acknowledgment
|
221
|
+
|
222
|
+
This rewrite was heavy inspired by the previous SimpleCaptcha Gems (licensed under MIT) by various authors:
|
223
|
+
|
224
|
+
* Sur Max
|
225
|
+
* Igor Galeta
|
226
|
+
* Azdaroth
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class SimpleCaptchaInput < Formtastic::Inputs::StringInput
|
2
|
+
def to_html
|
3
|
+
set_options!
|
4
|
+
captcha = SimpleCaptchaReloaded.generate_captcha(id: options[:captcha][:id], request: template.request)
|
5
|
+
input_wrapping do
|
6
|
+
label_html <<
|
7
|
+
image_tag(captcha) <<
|
8
|
+
captcha_key(captcha) <<
|
9
|
+
builder.text_field(method, input_html_options) <<
|
10
|
+
refresh_button(captcha)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_options!
|
15
|
+
default_options = {
|
16
|
+
refresh_button: true,
|
17
|
+
id: 'simple_captcha_wrapper'
|
18
|
+
}
|
19
|
+
options[:wrapper_html] ||= {}
|
20
|
+
options[:captcha] ||= {}
|
21
|
+
options[:captcha].reverse_merge!(default_options)
|
22
|
+
options[:wrapper_html][:id] ||= options[:captcha][:id]
|
23
|
+
end
|
24
|
+
|
25
|
+
def image_tag(captcha)
|
26
|
+
template.content_tag(:img, nil, src: captcha[:captcha_url], alt: 'Captcha', class: 'simple-captcha-image')
|
27
|
+
end
|
28
|
+
|
29
|
+
def captcha_key(captcha)
|
30
|
+
builder.hidden_field :captcha_key, value: captcha[:captcha_id]
|
31
|
+
end
|
32
|
+
|
33
|
+
def refresh_button(captcha)
|
34
|
+
template.content_tag :div, class: 'simple-captcha-reload' do
|
35
|
+
template.link_to captcha[:refresh_url], class: options[:captcha][:refresh_button_class], data: {remote: true} do
|
36
|
+
I18n.t('simple_captcha_reloaded.refresh_button_html')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -4,7 +4,7 @@ superclass = SimpleForm::Inputs::StringInput
|
|
4
4
|
if defined?(StringInput)
|
5
5
|
superclass = StringInput
|
6
6
|
end
|
7
|
-
class SimpleCaptchaInput < superclass
|
7
|
+
class SimpleForm::Inputs::SimpleCaptchaInput < superclass
|
8
8
|
def input(wrapper_options=nil)
|
9
9
|
set_options
|
10
10
|
@captcha = SimpleCaptchaReloaded.generate_captcha(id: options[:captcha][:id], request: template.request)
|
@@ -5,8 +5,10 @@ module SimpleCaptchaReloaded
|
|
5
5
|
isolate_namespace SimpleCaptchaReloaded
|
6
6
|
initializer "simple_captcha.load" do |app|
|
7
7
|
ActiveSupport.on_load :action_controller do
|
8
|
-
helper
|
9
|
-
|
8
|
+
if defined?(helper)
|
9
|
+
helper SimpleCaptchaReloaded::ViewHelper
|
10
|
+
ActionController::Base.send(:include, SimpleCaptchaReloaded::ControllerHelper)
|
11
|
+
end
|
10
12
|
end
|
11
13
|
app.middleware.use SimpleCaptchaReloaded::Middleware
|
12
14
|
end
|
@@ -14,7 +16,9 @@ module SimpleCaptchaReloaded
|
|
14
16
|
if defined?(SimpleForm)
|
15
17
|
require 'simple_captcha_reloaded/adapters/simple_form'
|
16
18
|
end
|
19
|
+
if defined?(Formtastic)
|
20
|
+
require 'simple_captcha_reloaded/adapters/formtastic'
|
21
|
+
end
|
17
22
|
end
|
18
|
-
|
19
23
|
end
|
20
24
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_captcha_reloaded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Wienert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- config/routes.rb
|
200
200
|
- db/migrate/20141129170641_create_simple_captcha_reloaded_simple_captcha_reloaded_data.rb
|
201
201
|
- lib/simple_captcha_reloaded.rb
|
202
|
+
- lib/simple_captcha_reloaded/adapters/formtastic.rb
|
202
203
|
- lib/simple_captcha_reloaded/adapters/simple_form.rb
|
203
204
|
- lib/simple_captcha_reloaded/config.rb
|
204
205
|
- lib/simple_captcha_reloaded/controller_helper.rb
|
@@ -230,9 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
231
|
version: '0'
|
231
232
|
requirements: []
|
232
233
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
234
|
+
rubygems_version: 2.6.13
|
234
235
|
signing_key:
|
235
236
|
specification_version: 4
|
236
237
|
summary: Captcha library which uses imagemagick to create captchas
|
237
238
|
test_files: []
|
238
|
-
has_rdoc:
|