simple_captcha2 0.4.0 → 0.4.2

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: e59bb7e3f61e3c9f11d561c0bd8d4092bd8d2777
4
- data.tar.gz: 8463a940c3d8388a788ce4f0284c84e23b363d71
3
+ metadata.gz: f8f865e98ebd2b44687dd85cba7e5dec3d5eaeae
4
+ data.tar.gz: cc24a8eb5fc210777e4633df42ad7c00a705c305
5
5
  SHA512:
6
- metadata.gz: c9b3b883001bef8e12d2a00ce43c9c3e090a7249db8c196679879bd537ceb7e72e6cc227414f586aa10a21a92a1bdb7011c838cdc931e0fd86c81ab327e3a38b
7
- data.tar.gz: 3754be1742f26b3210adcd52bdd85fcd1565e003756692a2f2d4cfba6f8d7db305c39d9e4ccfea24cc2e5390a91541a23b1e0e53e8a2ccc7b18468d07e069b12
6
+ metadata.gz: adac76147dd7b88e82f4761b338e8a7b83235ed2d8fcfc288e00dd50376c05231439d7ce29518d550cf02ccaaba6279d76ff1b860372b9fa5b945ca518f1d24d
7
+ data.tar.gz: 12b6d66de5ff5e9a2ac83a981c5ce12655748828bce13e9b96327fa2516d50446f4dbf3c41d040c070b3a8dfe3eff3b820135c4e6050e1a7265596e35fc2477b
data/README.md CHANGED
@@ -248,6 +248,14 @@ SimpleCaptcha.setup do |sc|
248
248
  end
249
249
  ```
250
250
 
251
+ You can setup in which format the reload of the captcha is executed:
252
+
253
+ ```ruby
254
+ SimpleCaptcha.setup do |sc|
255
+ sc.refresh_format = :prototype # or :jquery, or :plain_javascript default is :jquery
256
+ end
257
+ ```
258
+
251
259
 
252
260
  ### How to change the CSS for SimpleCaptcha DOM elements?
253
261
 
@@ -307,12 +315,11 @@ en:
307
315
  For testing, generate a temporary Rails dummy app inside test:
308
316
 
309
317
  ```bash
310
- rake dummy:setup
311
- rake app:db:migrate
312
- rake app:db:migrate RAILS_ENV=test
313
- export BUNDLE_GEMFILE=$PWD/Gemfile
314
- cd test/dummy && rake db:migrate db:test:prepare
315
- rake test
318
+ bundle
319
+ bundle exec rake dummy:setup
320
+ bundle exec rake app:db:migrate
321
+ bundle exec rake app:db:migrate RAILS_ENV=test
322
+ bundle exec rake test
316
323
  ```
317
324
 
318
325
  Please add test cases when adding new functionality. I started with some basic example integration tests for a very basic coverage.
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
15
15
  end
16
16
 
17
17
  APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
- if File.exists? APP_RAKEFILE
18
+ if File.exist? APP_RAKEFILE
19
19
  load 'rails/tasks/engine.rake'
20
20
  end
21
21
 
@@ -30,7 +30,7 @@ namespace :dummy do
30
30
 
31
31
  desc 'destroy dummy Rails app under test/dummy'
32
32
  task :destroy do
33
- FileUtils.rm_rf "test/dummy" if File.exists?("test/dummy")
33
+ FileUtils.rm_rf "test/dummy" if File.exist?("test/dummy")
34
34
  end
35
35
 
36
36
  desc 'redo'
@@ -51,6 +51,10 @@ module SimpleCaptcha
51
51
  mattr_accessor :implode
52
52
  @@implode = SimpleCaptcha::ImageHelpers::DEFAULT_IMPLODE
53
53
 
54
+ # 'jquery', 'prototype'
55
+ mattr_accessor :refresh_format
56
+ @@refresh_format = :jquery
57
+
54
58
  # command path
55
59
  mattr_accessor :image_magick_path
56
60
  @@image_magick_path = ''
@@ -15,7 +15,7 @@ module SimpleCaptcha #:nodoc
15
15
  # end
16
16
  def simple_captcha_valid?
17
17
  return true if SimpleCaptcha.always_pass
18
- return @_simple_captcha_result unless @_simple_captcha_result.nil?
18
+ return @_simple_captcha_result unless !defined?(@_simple_captcha_result) || @_simple_captcha_result.nil?
19
19
 
20
20
  if params[:captcha]
21
21
  captcha_key = params[:captcha_key] || session[:captcha]
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
  require 'rails'
3
- require 'simple_captcha'
4
3
 
5
4
  module SimpleCaptcha
6
5
  class Engine < ::Rails::Engine
@@ -9,6 +9,27 @@ module SimpleCaptcha
9
9
  :disposition => 'attachment'.freeze,
10
10
  }.freeze
11
11
 
12
+ REFRESH_FORMATS = {
13
+ :jquery => %Q{
14
+ $("#%{id}").attr('src', '%{url}');
15
+ $("#%{captcha_hidden_field_id}").attr('value', '%{key}');
16
+ }.freeze,
17
+ :plain_javascript => %Q{
18
+ var img = document.getElementById("%{id}");
19
+ if (img != null) {
20
+ img.src = "%{url}";
21
+ }
22
+ var hidden = document.getElementById("%{captcha_hidden_field_id}");
23
+ if (hidden != null) {
24
+ hidden.value = "%{key}";
25
+ }
26
+ }.freeze,
27
+ :prototype => %Q{
28
+ $("%{id}").setAttribute('src', '%{url}');
29
+ $("%{captcha_hidden_field_id}").setAttribute('value', '%{key}');
30
+ }.freeze,
31
+ }.freeze
32
+
12
33
  def initialize(app, options={})
13
34
  @app = app
14
35
  self
@@ -80,11 +101,11 @@ module SimpleCaptcha
80
101
  status = 200
81
102
  id = request.params['id']
82
103
  captcha_hidden_field_id = simple_captch_hidden_field_id(id)
104
+ format = SimpleCaptcha.refresh_format.to_sym
105
+ raise ::ArgumentError, "Format adapter '#{format}' is not available" unless format.in?(REFRESH_FORMATS)
106
+
107
+ body = REFRESH_FORMATS[format] % {id: id, url: url, captcha_hidden_field_id: captcha_hidden_field_id, key: key}
83
108
 
84
- body = %Q{
85
- $("##{id}").attr('src', '#{url}');
86
- $("##{ captcha_hidden_field_id }").attr('value', '#{key}');
87
- }
88
109
  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)
89
110
  [status, headers, [body]]
90
111
  end
@@ -19,13 +19,13 @@ module SimpleCaptcha
19
19
  end
20
20
 
21
21
  def remove_data(key)
22
- delete_all(["#{connection.quote_column_name(:key)} = ?", key])
22
+ where(["#{connection.quote_column_name(:key)} = ?", key]).delete_all
23
23
  clear_old_data(1.hour.ago)
24
24
  end
25
25
 
26
26
  def clear_old_data(time = 1.hour.ago)
27
27
  return unless Time === time
28
- delete_all(["#{connection.quote_column_name(:updated_at)} < ?", time])
28
+ where(["#{connection.quote_column_name(:updated_at)} < ?", time]).delete_all
29
29
  end
30
30
  end
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCaptcha
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.2".freeze
3
3
  end
@@ -56,7 +56,7 @@ module SimpleCaptcha #:nodoc
56
56
  options[:field_value] = set_simple_captcha_data(key, options)
57
57
  end
58
58
 
59
- defaults = {
59
+ {
60
60
  :image => simple_captcha_image(key, options),
61
61
  :label => I18n.t('simple_captcha.label'),
62
62
  :field => simple_captcha_field(options),
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_captcha2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavlo Galeta
8
8
  - Igor Galeta
9
9
  - Stefan Wienert
10
+ - Konrad Mallok
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2015-12-29 00:00:00.000000000 Z
14
+ date: 2017-02-03 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rails
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  version: '0'
131
132
  requirements: []
132
133
  rubyforge_project:
133
- rubygems_version: 2.4.8
134
+ rubygems_version: 2.5.1
134
135
  signing_key:
135
136
  specification_version: 4
136
137
  summary: SimpleCaptcha is the simplest and a robust captcha plugin.