simple_captcha2 0.3.2 → 0.3.3

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: eaae4d5f2ddd3caa10ef19b27e3792fd10dfff15
4
- data.tar.gz: 95060e2be4aec6e2a3cde73f811fdca235aacd1b
3
+ metadata.gz: 82daa59541bc47e50ecfb13d95b1672d953b0b79
4
+ data.tar.gz: 217de8368d88deb6720440ee8a69124ddbbcef83
5
5
  SHA512:
6
- metadata.gz: 41c2f4d97a08574b12fd6ab816ac180d69f0c2476f4eb31527082fe3b47cbec4aff724b399aa683e0682f9287b198f47bdadf21354cc56ea7480038c5c58f50c
7
- data.tar.gz: 6c049534725511c94c2fa734265bd143dbc833e577f51004bc895956889ad46f9015b495ee6b850c76b0d383e332efe82d5f3aa1b1e8f761f2fb4576218fcd55
6
+ metadata.gz: 0885a9d47688ebeb81930e1cb7716ad3c7aa3c453f67c067961985f05b232ee8b53c930709899c340ec3c172d921388cdd93410aafbdfaaa155db5f1fac57cba
7
+ data.tar.gz: f293939ccb2a80ce257ea200ed711fcfbbfd13bd5ed2cf526136d23b25187ac63a86a7b439b228140cbe13e2fac15845539c3dcec846901dde1b7887b7194d89
data/README.md CHANGED
@@ -45,7 +45,7 @@ After installation, follow these simple steps to setup the plugin. The setup wil
45
45
 
46
46
  ```bash
47
47
  rails generate simple_captcha
48
- rake db:migrate
48
+ rake db:migrate # Mongoid: skip this step and remove the migration
49
49
  ```
50
50
 
51
51
  ## Usage
@@ -96,6 +96,23 @@ class User < ActiveRecord::Base
96
96
  end
97
97
  ```
98
98
 
99
+ Mongoid:
100
+
101
+ ```ruby
102
+ class User
103
+ include SimpleCaptcha::ModelHelpers
104
+ apply_simple_captcha
105
+ end
106
+ ```
107
+
108
+ #### Strong parameters (Rails 4.x)
109
+
110
+ Must add them:
111
+
112
+ ```ruby
113
+ :captcha, :captcha_key
114
+ ```
115
+
99
116
  ####Form-Builder helper
100
117
 
101
118
  ```erb
@@ -174,6 +191,8 @@ You can also specify 'random' to select the random image style.
174
191
 
175
192
  * ``:distortion`` - handles the complexity of the image. The :distortion can be set to 'low', 'medium' or 'high'. Default is 'low'.
176
193
 
194
+ * ``:implode`` - handles the complexity of the image. The :implode can be set to 'none', 'low', 'medium' or 'high'. Default is 'medium'.
195
+
177
196
  Create "./config/initializers/simple_captcha.rb"
178
197
 
179
198
  ```ruby
@@ -200,6 +219,10 @@ SimpleCaptcha.setup do |sc|
200
219
  # default: low
201
220
  # possible values: 'low', 'medium', 'high', 'random'
202
221
  sc.distortion = 'medium'
222
+
223
+ # default: medium
224
+ # possible values: 'none', 'low', 'medium', 'high'
225
+ sc.implode = 'low'
203
226
  end
204
227
  ```
205
228
 
@@ -281,6 +304,7 @@ en:
281
304
  simple_captcha:
282
305
  placeholder: "Enter the image value"
283
306
  label: "Enter the code in the box:"
307
+ refresh_button_text: "Refresh"
284
308
  message:
285
309
  default: "Secret Code did not match with the Image"
286
310
  user: "The secret Image and code were different"
@@ -47,6 +47,10 @@ module SimpleCaptcha
47
47
  mattr_accessor :distortion
48
48
  @@distortion = 'low'
49
49
 
50
+ # 'none', 'low', 'medium', 'high'
51
+ mattr_accessor :implode
52
+ @@implode = SimpleCaptcha::ImageHelpers::DEFAULT_IMPLODE
53
+
50
54
  # command path
51
55
  mattr_accessor :image_magick_path
52
56
  @@image_magick_path = ''
@@ -55,6 +59,10 @@ module SimpleCaptcha
55
59
  mattr_accessor :tmp_path
56
60
  @@tmp_path = nil
57
61
 
62
+ # additive noise
63
+ mattr_accessor :noise
64
+ @@noise = 0
65
+
58
66
  def self.add_image_style(name, params = [])
59
67
  SimpleCaptcha::ImageHelpers.image_styles.update(name.to_s => params)
60
68
  end
@@ -16,6 +16,9 @@ module SimpleCaptcha #:nodoc
16
16
 
17
17
  DISTORTIONS = ['low', 'medium', 'high']
18
18
 
19
+ IMPLODES = { 'none' => 0, 'low' => 0.1, 'medium' => 0.2, 'high' => 0.3 }
20
+ DEFAULT_IMPLODE = 'medium'
21
+
19
22
  class << self
20
23
 
21
24
  def image_params(key = 'simply_blue')
@@ -43,6 +46,10 @@ module SimpleCaptcha #:nodoc
43
46
  when 'high' then return [4 + rand(2), 30 + rand(20)]
44
47
  end
45
48
  end
49
+
50
+ def implode
51
+ IMPLODES[SimpleCaptcha.implode] || IMPLODES[DEFAULT_IMPLODE]
52
+ end
46
53
  end
47
54
 
48
55
  if RUBY_VERSION < '1.9'
@@ -64,23 +71,14 @@ module SimpleCaptcha #:nodoc
64
71
  params = ImageHelpers.image_params(SimpleCaptcha.image_style).dup
65
72
  params << "-size #{SimpleCaptcha.image_size}"
66
73
  params << "-wave #{amplitude}x#{frequency}"
67
- #params << "-gravity 'Center'"
68
- params << "-gravity \"Center\""
74
+ params << "-gravity Center"
69
75
  params << "-pointsize 22"
70
- params << "-implode 0.2"
71
-
72
- dst = Tempfile.new(RUBY_VERSION < '1.9' ? 'simple_captcha.jpg' : ['simple_captcha', '.jpg'], SimpleCaptcha.tmp_path)
73
- dst.binmode
74
-
75
- #params << "label:#{text} '#{File.expand_path(dst.path)}'"
76
- params << "label:#{text} \"#{File.expand_path(dst.path)}\""
76
+ params << "-implode #{ImageHelpers.implode}"
77
+ params << "label:#{text}"
78
+ params << "-evaluate Uniform-noise #{SimpleCaptcha.noise}"
79
+ params << "jpeg:-"
77
80
 
78
81
  SimpleCaptcha::Utils::run("convert", params.join(' '))
79
-
80
- dst.close
81
-
82
- File.expand_path(dst.path)
83
- #dst
84
82
  end
85
83
  end
86
84
  end
@@ -39,7 +39,7 @@ module SimpleCaptcha
39
39
  #body = generate_simple_captcha_image(code)
40
40
  #headers['Content-Type'] = 'image/jpeg'
41
41
 
42
- send_file(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg')
42
+ send_data(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg')
43
43
  else
44
44
  [status, headers, body]
45
45
  end
@@ -61,6 +61,13 @@ module SimpleCaptcha
61
61
  [status, headers, response_body]
62
62
  end
63
63
 
64
+ def send_data(response_body, options = {})
65
+ status = options[:status] || 200
66
+ headers = {"Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'", "Content-Type" => options[:type], 'Content-Transfer-Encoding' => 'binary', 'Cache-Control' => 'private'}
67
+
68
+ [status, headers, [response_body]]
69
+ end
70
+
64
71
  def refresh_code(env)
65
72
  request = Rack::Request.new(env)
66
73
 
@@ -1,3 +1,3 @@
1
1
  module SimpleCaptcha
2
- VERSION = "0.3.2".freeze
2
+ VERSION = "0.3.3".freeze
3
3
  end
@@ -65,12 +65,7 @@ module SimpleCaptcha #:nodoc
65
65
  private
66
66
 
67
67
  def simple_captcha_image(simple_captcha_key, options = {})
68
- defaults = {}
69
- defaults[:time] = options[:time] || Time.now.to_i
70
-
71
- query = defaults.collect{ |key, value| "#{key}=#{value}" }.join('&')
72
- url = "#{ENV['RAILS_RELATIVE_URL_ROOT']}/simple_captcha?code=#{simple_captcha_key}&#{query}"
73
-
68
+ url = simple_captcha_image_url simple_captcha_key, options: options
74
69
  id = simple_captcha_image_id(options)
75
70
  tag('img', :src => url, :alt => 'captcha', :id => id)
76
71
  end
@@ -79,8 +74,13 @@ module SimpleCaptcha #:nodoc
79
74
  defaults = {}
80
75
  defaults[:time] = options[:time] || Time.now.to_i
81
76
 
82
- query = defaults.collect{ |key, value| "#{key}=#{value}" }.join('&')
83
- "#{ENV['RAILS_RELATIVE_URL_ROOT']}/simple_captcha?code=#{simple_captcha_key}&#{query}"
77
+ query = defaults.to_query
78
+ path = "/simple_captcha?code=#{simple_captcha_key}&#{query}"
79
+ if defined?(request) && request
80
+ "#{request.protocol}#{request.host_with_port}#{ENV['RAILS_RELATIVE_URL_ROOT']}#{path}"
81
+ else
82
+ "#{ENV['RAILS_RELATIVE_URL_ROOT']}#{path}"
83
+ end
84
84
  end
85
85
 
86
86
  def simple_captcha_field(options={})
@@ -133,8 +133,8 @@ module SimpleCaptcha #:nodoc
133
133
  return value
134
134
  end
135
135
 
136
- def simple_captcha_key(key_name = nil, request = request)
137
- local_session = request.try(:session) || session
136
+ def simple_captcha_key(key_name = nil, prequest = request)
137
+ local_session = prequest.try(:session) || session
138
138
  if key_name.nil?
139
139
  local_session[:captcha] ||= SimpleCaptcha::Utils.generate_key(local_session[:id].to_s, 'captcha')
140
140
  else
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.2
4
+ version: 0.3.3
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: 2014-06-12 00:00:00.000000000 Z
13
+ date: 2015-01-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails