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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56b2f0ffd426ed4af21105feeef7b12d53c79c3c
4
- data.tar.gz: f75531cc8139786aa6c8ac053414b642b5369d39
3
+ metadata.gz: c317ffb46efc02b32a774729631923802e597047
4
+ data.tar.gz: 38ddb5ce01cbdbc4bb626dfe13c999543e04cff1
5
5
  SHA512:
6
- metadata.gz: 9f5845f8550ef7b8de8ab5ac2c15f660b4975b8a58325d8fa3ab9d289b682f41e3c0607ba3327f1735a997841580f80a4e9ca524778d8c707148de264ba63c90
7
- data.tar.gz: 58053f230938ca6177d0b602f3049357a27c4bfd24a47249c08fcbd96fb9a596aba339151b76982ae292d327e4ef9318ca071a7025b8d8ee43d7fd47a7690f47
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
- raise MissingFile, "Cannot read file #{path}" unless File.file?(path) and File.readable?(path)
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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module SimpleCaptcha
4
- VERSION = "0.5.2".freeze
4
+ VERSION = "0.6.0".freeze
5
5
  end
@@ -57,12 +57,12 @@ module SimpleCaptcha #:nodoc
57
57
 
58
58
  private
59
59
 
60
- def simple_captcha_image(simple_captcha_key, options = {})
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=#{simple_captcha_key}&#{query}"
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.5.2
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-08 00:00:00.000000000 Z
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport