glebtv-simple_captcha 0.5.2 → 0.6.0
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/controller.rb +1 -1
- data/lib/simple_captcha/middleware.rb +6 -8
- data/lib/simple_captcha/version.rb +1 -1
- data/lib/simple_captcha/view.rb +2 -2
- 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: c317ffb46efc02b32a774729631923802e597047
|
4
|
+
data.tar.gz: 38ddb5ce01cbdbc4bb626dfe13c999543e04cff1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a3f9a98aed2cb7e3d8135d5516e7d7daec23285d85586cfe06ab3463c3d53046e304b0bef5fa1612db48be05d9c4b226ba47b5a8422904cf1112c243c1e74db
|
7
|
+
data.tar.gz: f20894ec31d8450f4d6ce6fbd1bd2fc286981e8424bf49a79af2890c2ea3a9703e68b893232365d65e51bd89fb6e460bbbf0b5effe6b6a1e937d39b0619dd1b6
|
@@ -18,7 +18,7 @@ module SimpleCaptcha #:nodoc
|
|
18
18
|
|
19
19
|
if params[:captcha]
|
20
20
|
data = SimpleCaptcha::Utils::simple_captcha_value(session[:captcha])
|
21
|
-
result = data == params[:captcha].delete(" ").upcase
|
21
|
+
result = (!data.nil? && data.upcase == params[:captcha].delete(" ").upcase)
|
22
22
|
SimpleCaptcha::Utils::simple_captcha_passed!(session[:captcha]) if result
|
23
23
|
return result
|
24
24
|
else
|
@@ -26,13 +26,7 @@ module SimpleCaptcha
|
|
26
26
|
request = Rack::Request.new(env)
|
27
27
|
code = request.params["code"]
|
28
28
|
body = []
|
29
|
-
|
30
29
|
if !code.blank? && Utils::simple_captcha_value(code)
|
31
|
-
#status, headers, body = @app.call(env)
|
32
|
-
#status = 200
|
33
|
-
#body = generate_simple_captcha_image(code)
|
34
|
-
#headers['Content-Type'] = 'image/jpeg'
|
35
|
-
|
36
30
|
return send_file(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg')
|
37
31
|
end
|
38
32
|
|
@@ -44,13 +38,17 @@ module SimpleCaptcha
|
|
44
38
|
end
|
45
39
|
|
46
40
|
def send_file(path, options = {})
|
47
|
-
|
41
|
+
unless File.file?(path) and File.readable?(path)
|
42
|
+
puts "[simple captcha] Cannot read file #{path}"
|
43
|
+
raise MissingFile, "Cannot read file #{path}"
|
44
|
+
end
|
48
45
|
|
49
46
|
options[:filename] ||= File.basename(path) unless options[:url_based_filename]
|
50
47
|
|
51
48
|
status = options[:status] || 200
|
52
49
|
headers = {"Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'", "Content-Type" => options[:type], 'Content-Transfer-Encoding' => 'binary', 'Cache-Control' => 'private'}
|
53
|
-
response_body = File.open(path, "rb")
|
50
|
+
response_body = [File.open(path, "rb").read]
|
51
|
+
File.delete(path)
|
54
52
|
|
55
53
|
[status, headers, response_body]
|
56
54
|
end
|
data/lib/simple_captcha/view.rb
CHANGED
@@ -57,12 +57,12 @@ module SimpleCaptcha #:nodoc
|
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
|
-
def simple_captcha_image(
|
60
|
+
def simple_captcha_image(sc_key, options = {})
|
61
61
|
defaults = {}
|
62
62
|
defaults[:time] = options[:time] || Time.now.to_i
|
63
63
|
|
64
64
|
query = defaults.collect{ |key, value| "#{key}=#{value}" }.join('&')
|
65
|
-
url = "/simple_captcha?code=#{
|
65
|
+
url = "/simple_captcha?code=#{sc_key}&#{query}"
|
66
66
|
|
67
67
|
"<img src='#{url}' alt='captcha' />".html_safe
|
68
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glebtv-simple_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GlebTv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|