rucaptcha 2.0.3 → 2.1.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: ff5dc2eab0dce97fc48b2785dd334c40a4e56478
4
- data.tar.gz: 6260f7dfde2dd1c4ab3ec7724d8e1e3d207f0ac8
3
+ metadata.gz: 7eb3d814d1abc1f5a0e0697ab96db602c4e8a716
4
+ data.tar.gz: c57741d52df52d8b57fa724a55ece1240cd028c3
5
5
  SHA512:
6
- metadata.gz: 90b1cf57de8baa5a48411565437bc71eec34753a4a5fdf88b9b58f054d00a75b1d3df84aa2cd0544c7287f0ff5d59bf897a9c355fe9ca55e04355d07ac8cd30b
7
- data.tar.gz: f6ffd1634b07751ebbf19207ef45864c3bf4ff99c2333e1c7a5510fa3db844a3dbbad5808a5ec119322dfffc52781feb08d49fcaabb623a8b335cdf2b3bc14c0
6
+ metadata.gz: d636f015eb7350878264ea6b5f9b966a2ff7cd7a9ca42d932f3b6ad00814ad0cd997e407ffdea89399e7db95758626b04f57a9bc9a635837022d7153a0ea555d
7
+ data.tar.gz: 1333a867127f01c83fe2554d453c7fd9061581d167aeccf2bd8ea4bd5ceef45d0f71e884d5c206fef179d7a2b654329aa95e58dca0b0b0331f2109dd5cb2c353
@@ -1,3 +1,11 @@
1
+ 2.1.0
2
+ -----
3
+
4
+ - Mount Router by default, not need config now.
5
+ - Default use [:file_store, 'tmp/cache/rucaptcha/session'] as RuCaptcha.config.cache_store, now it can work without any configurations.
6
+
7
+ > NOTE: But you still need care about `config.cache_store` to setup on a right way.
8
+
1
9
  2.0.3
2
10
  -----
3
11
 
data/README.md CHANGED
@@ -35,28 +35,20 @@ RuCaptcha.configure do
35
35
   # self.style = :colorful
36
36
  # Custom captcha code expire time if you need, default: 2 minutes
37
37
  # self.expires_in = 120
38
-  # [Requirement/重要]
38
+  # [Requirement / 重要]
39
39
  # Store Captcha code where, this config more like Rails config.cache_store
40
40
  # default: Read config info from `Rails.application.config.cache_store`
41
41
  # But RuCaptcha requirements cache_store not in [:null_store, :memory_store, :file_store]
42
-  # 默认:会从 Rails 配置的 cache_store 里面读取相同的配置信息,用于存储验证码字符
42
+  # 默认:会从 Rails 配置的 cache_store 里面读取相同的配置信息,并尝试用可以运行的方式,用于存储验证码字符
43
43
   # 但如果是 [:null_store, :memory_store, :file_store] 之类的,你可以通过下面的配置项单独给 RuCaptcha 配置 cache_store
44
44
   self.cache_store = :mem_cache_store
45
45
  end
46
46
  ```
47
47
 
48
- Edit `config/routes.rb`, add the following code:
49
-
50
- ```rb
51
- Rails.application.routes.draw do
52
- ...
53
- mount RuCaptcha::Engine => "/rucaptcha"
54
- ...
55
- end
56
- ```
57
-
58
48
  Controller `app/controller/account_controller.rb`
59
49
 
50
+ When you called `verify_rucaptcha?`, it will uses value from `params[:_rucaptcha]` to validation.
51
+
60
52
  ```rb
61
53
  class AccountController < ApplicationController
62
54
  def create
@@ -68,6 +60,17 @@ class AccountController < ApplicationController
68
60
  end
69
61
  end
70
62
  end
63
+
64
+ class ForgotPasswordController < ApplicationController
65
+ def create
66
+ # without any args
67
+ if verify_rucaptcha?
68
+ to_send_email
69
+ else
70
+ redirect_to '/forgot-password', alert: 'Invalid captcha code.'
71
+ end
72
+ end
73
+ end
71
74
  ```
72
75
 
73
76
  > TIP: Sometime you may need keep last verified captcha code in session on `verify_rucaptcha?` method call, you can use `keep_session: true`. For example: `verify_rucaptcha? @user, keep_session: true`.
@@ -75,13 +78,17 @@ end
75
78
  View `app/views/account/new.html.erb`
76
79
 
77
80
  ```erb
78
- <form>
81
+ <form method="POST">
79
82
  ...
80
83
  <div class="form-group">
81
84
  <%= rucaptcha_input_tag(class: 'form-control', placeholder: 'Input Captcha') %>
82
85
  <%= rucaptcha_image_tag(alt: 'Captcha') %>
83
86
  </div>
84
87
  ...
88
+
89
+ <div class="form-group">
90
+ <button type="submit" class="btn btn-primary">Submit</button>
91
+ </div>
85
92
  </form>
86
93
  ```
87
94
 
@@ -19,8 +19,9 @@ module RuCaptcha
19
19
  if Rails.application
20
20
  @config.cache_store = Rails.application.config.cache_store
21
21
  else
22
- @config.cache_store = :null_store
22
+ @config.cache_store = :mem_cache_store
23
23
  end
24
+ @config.cache_store
24
25
  @config
25
26
  end
26
27
 
@@ -32,6 +33,27 @@ module RuCaptcha
32
33
  style = config.style == :colorful ? 1 : 0
33
34
  self.create(style)
34
35
  end
36
+
37
+ def check_cache_store!
38
+ cache_store = RuCaptcha.config.cache_store
39
+ store_name = cache_store.is_a?(Array) ? cache_store.first : cache_store
40
+ if [:memory_store, :null_store, :file_store].include?(store_name)
41
+ RuCaptcha.config.cache_store = [:file_store, Rails.root.join('tmp/cache/rucaptcha/session')]
42
+
43
+ puts "
44
+
45
+ RuCaptcha's cache_store requirements are stored across processes and machines,
46
+ such as :mem_cache_store, :redis_store, or other distributed storage.
47
+ But your current set is #{cache_store}, it has changed to :file_store for working.
48
+ NOTE: :file_store is still not a good way, it only works with single server case.
49
+
50
+ Please make config file `config/initializes/rucaptcha.rb` to setup `cache_store`.
51
+ More infomation please read GitHub RuCaptcha README file.
52
+ https://github.com/huacnlee/rucaptcha
53
+
54
+ "
55
+ end
56
+ end
35
57
  end
36
58
  end
37
59
 
@@ -2,26 +2,14 @@ module RuCaptcha
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace RuCaptcha
4
4
 
5
- initializer 'rucaptcha.prepend.cache' do
6
- cache_store = RuCaptcha.config.cache_store
7
- store_name = cache_store.is_a?(Array) ? cache_store.first : cache_store
8
- if [:memory_store, :null_store, :file_store].include?(store_name)
9
- msg = "
10
-
11
- RuCaptcha's cache_store requirements are stored across processes and machines,
12
- such as :mem_cache_store, :redis_store, or other distributed storage.
13
- But your current set is :#{store_name}.
14
-
15
- Please make config file `config/initializes/rucaptcha.rb` to setup `cache_store`.
16
- More infomation please read GitHub RuCaptcha README file.
17
-
18
- "
19
- if store_name == :null_store
20
- raise msg
21
- else
22
- puts msg
23
- end
5
+ initializer 'rucaptcha.init' do |app|
6
+ # https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_dispatch/routing/route_set.rb#L268
7
+ # `app.routes.append` start from Rails 3.2 - 5.0
8
+ app.routes.append do
9
+ mount RuCaptcha::Engine => '/rucaptcha'
24
10
  end
11
+
12
+ RuCaptcha.check_cache_store!
25
13
  end
26
14
  end
27
15
  end
@@ -1,3 +1,3 @@
1
1
  module RuCaptcha
2
- VERSION = '2.0.3'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-15 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.5.2
87
+ rubygems_version: 2.6.8
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: This is a Captcha gem for Rails Applications. It drawing captcha image with