simple_captcha2 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_captcha.rb +6 -0
- data/lib/simple_captcha/form_builder.rb +1 -1
- data/lib/simple_captcha/middleware.rb +3 -2
- data/lib/simple_captcha/utils.rb +1 -1
- data/lib/simple_captcha/version.rb +1 -1
- data/lib/simple_captcha/view.rb +18 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e289c77c2ba483a5f6a97578cc107ce7b6429d
|
4
|
+
data.tar.gz: e9bbd53602642e958644e2daeefaca5f260cab40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5da26157f9f1dbc8df22fed158939865e01b813e94506dda4ee329359fd5bee28f64c5e576b7c13604a582fa09e43884dd7550330f224f761165cf936d4c30c2
|
7
|
+
data.tar.gz: 2e5330b6f248b00862c1eb36c4c6568ff743ced1e42f2ed8ba020300db067b1a8bad39926808e694b369314f6de16b4ac663e7108e9c6f97311a072c8224e424
|
data/lib/simple_captcha.rb
CHANGED
@@ -63,6 +63,12 @@ module SimpleCaptcha
|
|
63
63
|
mattr_accessor :noise
|
64
64
|
@@noise = 0
|
65
65
|
|
66
|
+
mattr_accessor :extra_response_headers
|
67
|
+
@@extra_response_headers = {}
|
68
|
+
|
69
|
+
mattr_accessor :partial_path
|
70
|
+
@@partial_path = 'simple_captcha/simple_captcha'
|
71
|
+
|
66
72
|
def self.add_image_style(name, params = [])
|
67
73
|
SimpleCaptcha::ImageHelpers.image_styles.update(name.to_s => params)
|
68
74
|
end
|
@@ -36,7 +36,7 @@ module SimpleCaptcha
|
|
36
36
|
html[:placeholder] = options[:placeholder] || I18n.t('simple_captcha.placeholder')
|
37
37
|
|
38
38
|
text_field(:captcha, html) +
|
39
|
-
hidden_field(:captcha_key, {:value => options[:field_value]})
|
39
|
+
hidden_field(:captcha_key, {:value => options[:field_value], :id => simple_captch_hidden_field_id(options)})
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -79,12 +79,13 @@ module SimpleCaptcha
|
|
79
79
|
|
80
80
|
status = 200
|
81
81
|
id = request.params['id']
|
82
|
+
captcha_hidden_field_id = simple_captch_hidden_field_id(id)
|
82
83
|
|
83
84
|
body = %Q{
|
84
85
|
$("##{id}").attr('src', '#{url}');
|
85
|
-
$("
|
86
|
+
$("##{ captcha_hidden_field_id }").attr('value', '#{key}');
|
86
87
|
}
|
87
|
-
headers = {'Content-Type' => 'text/javascript; charset=utf-8', "Content-Disposition" => "inline; filename='captcha.js'", "Content-Length" => body.length.to_s}
|
88
|
+
headers = {'Content-Type' => 'text/javascript; charset=utf-8', "Content-Disposition" => "inline; filename='captcha.js'", "Content-Length" => body.length.to_s}.merge(SimpleCaptcha.extra_response_headers)
|
88
89
|
[status, headers, [body]]
|
89
90
|
end
|
90
91
|
end
|
data/lib/simple_captcha/utils.rb
CHANGED
data/lib/simple_captcha/view.rb
CHANGED
@@ -42,7 +42,11 @@ module SimpleCaptcha #:nodoc
|
|
42
42
|
# Find more detailed examples with sample images here on my blog http://EXPRESSICA.com
|
43
43
|
#
|
44
44
|
# All Feedbacks/CommentS/Issues/Queries are welcome.
|
45
|
-
def show_simple_captcha(options={})
|
45
|
+
def show_simple_captcha(options = {})
|
46
|
+
render :partial => SimpleCaptcha.partial_path, :locals => { :simple_captcha_options => simple_captcha_options(options) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def simple_captcha_options(options = {})
|
46
50
|
key = simple_captcha_key(options[:object])
|
47
51
|
if options[:multiple] === false
|
48
52
|
# It's not the first captcha, we only need to return the key
|
@@ -58,8 +62,6 @@ module SimpleCaptcha #:nodoc
|
|
58
62
|
:field => simple_captcha_field(options),
|
59
63
|
:refresh_button => simple_captcha_refresh_button(options),
|
60
64
|
}.merge(options)
|
61
|
-
|
62
|
-
render :partial => 'simple_captcha/simple_captcha', :locals => { :simple_captcha_options => defaults }
|
63
65
|
end
|
64
66
|
|
65
67
|
private
|
@@ -76,6 +78,10 @@ module SimpleCaptcha #:nodoc
|
|
76
78
|
|
77
79
|
query = defaults.to_query
|
78
80
|
path = "/simple_captcha?code=#{simple_captcha_key}&#{query}"
|
81
|
+
build_url(options, path)
|
82
|
+
end
|
83
|
+
|
84
|
+
def build_url(options, path)
|
79
85
|
if defined?(request) && request
|
80
86
|
"#{request.protocol}#{request.host_with_port}#{ENV['RAILS_RELATIVE_URL_ROOT']}#{path}"
|
81
87
|
else
|
@@ -90,10 +96,10 @@ module SimpleCaptcha #:nodoc
|
|
90
96
|
|
91
97
|
if options[:object]
|
92
98
|
text_field(options[:object], :captcha, html.merge(:value => '')) +
|
93
|
-
hidden_field(options[:object], :captcha_key, {:value => options[:field_value]})
|
99
|
+
hidden_field(options[:object], :captcha_key, {:value => options[:field_value], :id => simple_captch_hidden_field_id(options)})
|
94
100
|
else
|
95
101
|
text_field_tag(:captcha, nil, html) +
|
96
|
-
hidden_field_tag(:captcha_key, options[:field_value])
|
102
|
+
hidden_field_tag(:captcha_key, options[:field_value], :id => simple_captch_hidden_field_id(options))
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
@@ -103,13 +109,19 @@ module SimpleCaptcha #:nodoc
|
|
103
109
|
|
104
110
|
text = options[:refresh_button_text] || I18n.t('simple_captcha.refresh_button_text', default: 'Refresh')
|
105
111
|
|
106
|
-
|
112
|
+
url = build_url(options, "/simple_captcha?id=#{simple_captcha_image_id(options)}")
|
113
|
+
link_to(text, url, html)
|
107
114
|
end
|
108
115
|
|
109
116
|
def simple_captcha_image_id(options={})
|
110
117
|
"simple_captcha-#{options[:field_value][0..10]}"
|
111
118
|
end
|
112
119
|
|
120
|
+
def simple_captch_hidden_field_id(image_id)
|
121
|
+
image_id = simple_captcha_image_id(image_id) if image_id.is_a?(Hash)
|
122
|
+
"simple-captcha-hidden-field-#{ image_id }"
|
123
|
+
end
|
124
|
+
|
113
125
|
def set_simple_captcha_data(key, options={})
|
114
126
|
code_type = options[:code_type]
|
115
127
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_captcha2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavlo Galeta
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|