galetahub-simple_captcha 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,7 +28,7 @@ backward compatibility with previous versions of Rails.
28
28
 
29
29
  or
30
30
 
31
- gem 'galetahub-simple_captcha', :require => 'simple_captcha', :git => 'git://github.com/galetahub/simple-captcha.git'
31
+ gem 'simple_captcha', :git => 'git://github.com/galetahub/simple-captcha.git'
32
32
 
33
33
  ==Setup
34
34
 
@@ -69,7 +69,7 @@ In the view file within the form tags write this code
69
69
 
70
70
  and in the model class add this code
71
71
 
72
- class User < ActiveRecord::Basse
72
+ class User < ActiveRecord::Base
73
73
  apply_simple_captcha
74
74
  end
75
75
 
@@ -166,6 +166,13 @@ You can provide the path where image_magick is installed as well:
166
166
  sc.image_magick_path = '/usr/bin' # you can check this from console by running: which convert
167
167
  end
168
168
 
169
+ You can provide the path where should be stored tmp files.
170
+ It's usefull when you dont have acces to /tmp (default directory)
171
+
172
+ SimpleCaptcha.setup do |sc|
173
+ sc.tmp_path = '/tmp' # or somewhere in project eg. Rails.root.join('tmp/simple_captcha').to_s, make shure directory exists
174
+ end
175
+
169
176
 
170
177
  ===How to change the CSS for SimpleCaptcha DOM elements?
171
178
  You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file.
@@ -6,12 +6,18 @@ module SimpleCaptcha
6
6
  autoload :ImageHelpers, 'simple_captcha/image'
7
7
  autoload :ViewHelper, 'simple_captcha/view'
8
8
  autoload :ControllerHelpers, 'simple_captcha/controller'
9
- autoload :ModelHelpers, 'simple_captcha/active_record'
10
9
 
11
10
  autoload :FormBuilder, 'simple_captcha/form_builder'
12
11
  autoload :CustomFormBuilder, 'simple_captcha/formtastic'
13
12
 
14
- autoload :SimpleCaptchaData, 'simple_captcha/simple_captcha_data'
13
+ if defined?(ActiveRecord)
14
+ autoload :ModelHelpers, 'simple_captcha/active_record'
15
+ autoload :SimpleCaptchaData, 'simple_captcha/simple_captcha_data'
16
+ else
17
+ autoload :SimpleCaptchaData, 'simple_captcha/simple_captcha_data_mongoid.rb'
18
+ end
19
+
20
+
15
21
  autoload :Middleware, 'simple_captcha/middleware'
16
22
 
17
23
  mattr_accessor :image_size
@@ -40,6 +46,10 @@ module SimpleCaptcha
40
46
  mattr_accessor :image_magick_path
41
47
  @@image_magick_path = ''
42
48
 
49
+ # tmp directory
50
+ mattr_accessor :tmp_path
51
+ @@tmp_path = nil
52
+
43
53
  def self.add_image_style(name, params = [])
44
54
  SimpleCaptcha::ImageHelpers.image_styles.update(name.to_s => params)
45
55
  end
@@ -40,6 +40,7 @@ module SimpleCaptcha #:nodoc
40
40
  extend ClassMethods
41
41
 
42
42
  attr_accessor :captcha, :captcha_key
43
+ attr_accessible :captcha, :captcha_key
43
44
  end
44
45
  end
45
46
  end
@@ -54,12 +55,14 @@ module SimpleCaptcha #:nodoc
54
55
  end
55
56
 
56
57
  def is_captcha_valid?
58
+ return true if Rails.env.test?
59
+
57
60
  if captcha && captcha.upcase.delete(" ") == SimpleCaptcha::Utils::simple_captcha_value(captcha_key)
58
61
  SimpleCaptcha::Utils::simple_captcha_passed!(captcha_key)
59
62
  return true
60
63
  else
61
64
  message = simple_captcha_options[:message] || I18n.t(self.class.model_name.downcase, :scope => [:simple_captcha, :message], :default => :default)
62
- simple_captcha_options[:add_to_base] ? errors.add_to_base(message) : errors.add(:captcha, message)
65
+ simple_captcha_options[:add_to_base] ? errors.add(:base, message) : errors.add(:captcha, message)
63
66
  return false
64
67
  end
65
68
  end
@@ -17,7 +17,7 @@ module SimpleCaptcha #:nodoc
17
17
  return true if Rails.env.test?
18
18
 
19
19
  if params[:captcha]
20
- data = SimpleCaptcha::Utils::simple_captcha_value(session[:captcha])
20
+ data = SimpleCaptcha::Utils::simple_captcha_value(params[:captcha_key] || session[:captcha])
21
21
  result = data == params[:captcha].delete(" ").upcase
22
22
  SimpleCaptcha::Utils::simple_captcha_passed!(session[:captcha]) if result
23
23
  return result
@@ -3,6 +3,9 @@ module SimpleCaptcha
3
3
  def self.included(base)
4
4
  base.send(:include, SimpleCaptcha::ViewHelper)
5
5
  base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods)
6
+ base.send(:include, ActionView::Helpers)
7
+ base.send(:include, Sprockets::Helpers::RailsHelper)
8
+ base.send(:include, Sprockets::Helpers::IsolatedHelper)
6
9
 
7
10
  base.delegate :render, :session, :to => :template
8
11
  end
@@ -26,7 +29,11 @@ module SimpleCaptcha
26
29
  end
27
30
 
28
31
  def simple_captcha_field(options={})
29
- text_field(:captcha, :value => '', :autocomplete => 'off') +
32
+ html = {:autocomplete => 'off', :required => 'required', :value => ''}
33
+ html.merge!(options[:input_html] || {})
34
+ html[:placeholder] = options[:placeholder] || I18n.t('simple_captcha.placeholder')
35
+
36
+ text_field(:captcha, html) +
30
37
  hidden_field(:captcha_key, {:value => options[:field_value]})
31
38
  end
32
39
  end
@@ -1,5 +1,5 @@
1
1
  module SimpleCaptcha
2
- class CustomFormBuilder < Formtastic::SemanticFormBuilder
2
+ class CustomFormBuilder < Formtastic::FormBuilder
3
3
 
4
4
  private
5
5
 
@@ -64,14 +64,16 @@ module SimpleCaptcha #:nodoc
64
64
  params = ImageHelpers.image_params(SimpleCaptcha.image_style).dup
65
65
  params << "-size #{SimpleCaptcha.image_size}"
66
66
  params << "-wave #{amplitude}x#{frequency}"
67
- params << "-gravity 'Center'"
67
+ #params << "-gravity 'Center'"
68
+ params << "-gravity \"Center\""
68
69
  params << "-pointsize 22"
69
70
  params << "-implode 0.2"
70
71
 
71
- dst = RUBY_VERSION < '1.9' ? Tempfile.new('simple_captcha.jpg') : Tempfile.new(['simple_captcha', '.jpg'])
72
+ dst = Tempfile.new(RUBY_VERSION < '1.9' ? 'simple_captcha.jpg' : ['simple_captcha', '.jpg'], SimpleCaptcha.tmp_path)
72
73
  dst.binmode
73
74
 
74
- params << "label:#{text} '#{File.expand_path(dst.path)}'"
75
+ #params << "label:#{text} '#{File.expand_path(dst.path)}'"
76
+ params << "label:#{text} \"#{File.expand_path(dst.path)}\""
75
77
 
76
78
  SimpleCaptcha::Utils::run("convert", params.join(' '))
77
79
 
@@ -1,6 +1,16 @@
1
1
  module SimpleCaptcha
2
2
  class SimpleCaptchaData < ::ActiveRecord::Base
3
- set_table_name "simple_captcha_data"
3
+ def self.rails3?
4
+ ::ActiveRecord::VERSION::MAJOR == 3
5
+ end
6
+
7
+ if rails3?
8
+ # Fixes deprecation warning in Rails 3.2:
9
+ # DEPRECATION WARNING: Calling set_table_name is deprecated. Please use `self.table_name = 'the_name'` instead.
10
+ self.table_name = "simple_captcha_data"
11
+ else
12
+ set_table_name "simple_captcha_data"
13
+ end
4
14
 
5
15
  attr_accessible :key, :value
6
16
 
@@ -0,0 +1,25 @@
1
+ module SimpleCaptcha
2
+ class SimpleCaptchaData
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :key, type: String
7
+ field :value, type: String
8
+
9
+ class << self
10
+ def get_data(key)
11
+ data = where(:key => key).first || new(:key => key)
12
+ end
13
+
14
+ def remove_data(key)
15
+ where(:key => key).delete_all
16
+ clear_old_data(1.hour.ago)
17
+ end
18
+
19
+ def clear_old_data(time = 1.hour.ago)
20
+ return unless Time === time
21
+ where(:updated_at.lte => time).delete_all
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module SimpleCaptcha
3
- VERSION = "0.1.3".freeze
3
+ VERSION = "0.1.4".freeze
4
4
  end
@@ -62,17 +62,22 @@ module SimpleCaptcha #:nodoc
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 = "#{ENV['RAILS_RELATIVE_URL_ROOT']}/simple_captcha?code=#{simple_captcha_key}&#{query}"
66
66
 
67
- "<img src='#{url}' alt='captcha' />".html_safe
67
+ tag('img', :src => url, :alt => 'captcha')
68
68
  end
69
69
 
70
70
  def simple_captcha_field(options={})
71
+ html = {:autocomplete => 'off', :required => 'required'}
72
+ html.merge!(options[:input_html] || {})
73
+ html[:placeholder] = options[:placeholder] || I18n.t('simple_captcha.placeholder')
74
+
71
75
  if options[:object]
72
- text_field(options[:object], :captcha, :value => '', :autocomplete => 'off') +
76
+ text_field(options[:object], :captcha, html.merge(:value => '')) +
73
77
  hidden_field(options[:object], :captcha_key, {:value => options[:field_value]})
74
78
  else
75
- text_field_tag(:captcha, nil, :autocomplete => 'off')
79
+ text_field_tag(:captcha, nil, html) +
80
+ hidden_field_tag(:captcha_key, options[:field_value])
76
81
  end
77
82
  end
78
83
 
metadata CHANGED
@@ -1,84 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: galetahub-simple_captcha
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Pavlo Galeta
14
9
  - Igor Galeta
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-12-20 00:00:00 Z
13
+ date: 2013-04-08 00:00:00.000000000 Z
20
14
  dependencies: []
21
-
22
- description: SimpleCaptcha is available to be used with Rails 3 or above and also it provides the backward compatibility with previous versions of Rails.
15
+ description: SimpleCaptcha is available to be used with Rails 3 or above and also
16
+ it provides the backward compatibility with previous versions of Rails.
23
17
  email: galeta.igor@gmail.com
24
18
  executables: []
25
-
26
19
  extensions: []
27
-
28
- extra_rdoc_files:
20
+ extra_rdoc_files:
29
21
  - README.rdoc
30
- files:
31
- - lib/generators/simple_captcha_generator.rb
32
- - lib/generators/templates/migration.rb
33
- - lib/generators/templates/partial.erb
34
- - lib/generators/USAGE
22
+ files:
35
23
  - lib/simple_captcha.rb
36
- - lib/simple_captcha/engine.rb
37
- - lib/simple_captcha/utils.rb
38
- - lib/simple_captcha/controller.rb
39
- - lib/simple_captcha/view.rb
40
- - lib/simple_captcha/formtastic.rb
41
24
  - lib/simple_captcha/form_builder.rb
25
+ - lib/simple_captcha/controller.rb
26
+ - lib/simple_captcha/image.rb
42
27
  - lib/simple_captcha/simple_captcha_data.rb
43
- - lib/simple_captcha/middleware.rb
44
- - lib/simple_captcha/version.rb
45
28
  - lib/simple_captcha/active_record.rb
46
- - lib/simple_captcha/image.rb
29
+ - lib/simple_captcha/version.rb
30
+ - lib/simple_captcha/engine.rb
31
+ - lib/simple_captcha/simple_captcha_data_mongoid.rb
32
+ - lib/simple_captcha/formtastic.rb
33
+ - lib/simple_captcha/middleware.rb
34
+ - lib/simple_captcha/utils.rb
35
+ - lib/simple_captcha/view.rb
36
+ - lib/generators/templates/partial.erb
37
+ - lib/generators/templates/migration.rb
38
+ - lib/generators/simple_captcha_generator.rb
39
+ - lib/generators/USAGE
47
40
  - Rakefile
48
41
  - README.rdoc
49
42
  - test/simple_captcha_test.rb
50
- homepage: http://github.com/galetahub/simple-captcha
43
+ homepage: http://github.com/izzm/simple-captcha
51
44
  licenses: []
52
-
53
45
  post_install_message:
54
46
  rdoc_options: []
55
-
56
- require_paths:
47
+ require_paths:
57
48
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
59
50
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- hash: 3
64
- segments:
65
- - 0
66
- version: "0"
67
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
56
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
76
61
  requirements: []
77
-
78
- rubyforge_project: galetahub-simple_captcha
79
- rubygems_version: 1.8.10
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.25
80
64
  signing_key:
81
65
  specification_version: 3
82
66
  summary: SimpleCaptcha is the simplest and a robust captcha plugin.
83
- test_files:
67
+ test_files:
84
68
  - test/simple_captcha_test.rb