rucaptcha 2.5.3 → 2.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +133 -89
- data/README.md +2 -1
- data/app/controllers/ru_captcha/captcha_controller.rb +4 -3
- data/config/routes.rb +1 -1
- data/ext/rucaptcha/extconf.rb +2 -2
- data/lib/rucaptcha.rb +23 -24
- data/lib/rucaptcha/cache.rb +2 -1
- data/lib/rucaptcha/controller_helpers.rb +9 -18
- data/lib/rucaptcha/engine.rb +2 -2
- data/lib/rucaptcha/version.rb +1 -1
- data/lib/rucaptcha/view_helpers.rb +8 -8
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 865e51c997ad77d19192b1da3cef9786d7dc2178ebc4528db6e281ce8d4d47e9
|
|
4
|
+
data.tar.gz: e1b03e54771aabc0ee2b10497b4a1f7215f2e1273908e00feb63456a30787743
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b6cee07b419390aa91c99708f1d788f2507d0e87b4d729ed08a6d664bf527d6358bd5a6187ce29e2da1f05e95778dcb53fc07f749399564802766b40dd1f6b7
|
|
7
|
+
data.tar.gz: d48d9cb0ff756ec16b6121314e5f13c85c4051d17cc11d049f5f246f7231db6fea9f335724fe6c67106b9f38d09ea4403aebeb853356c2b602802f01885c7378
|
data/CHANGELOG.md
CHANGED
|
@@ -1,93 +1,110 @@
|
|
|
1
|
-
2.5.
|
|
2
|
-
|
|
1
|
+
## 2.5.4
|
|
2
|
+
|
|
3
|
+
- Fix: rucaptcha input maxlength attribute with config value.
|
|
4
|
+
|
|
5
|
+
2.5.3
|
|
6
|
+
|
|
7
|
+
---
|
|
3
8
|
|
|
4
9
|
- Fix session invalid warning, only for development env;
|
|
5
10
|
|
|
6
|
-
2.5.2
|
|
7
|
-
|
|
11
|
+
2.5.2
|
|
12
|
+
|
|
13
|
+
---
|
|
8
14
|
|
|
9
15
|
- Fix session.id error with upgrade Rails 6.0.2.1 or Rack 2.0.8 (#84)
|
|
10
16
|
|
|
11
|
-
2.5.1
|
|
12
|
-
|
|
17
|
+
2.5.1
|
|
18
|
+
|
|
19
|
+
---
|
|
13
20
|
|
|
14
21
|
- Fix invalid module name error. (#78)
|
|
15
22
|
|
|
16
|
-
2.5.0
|
|
17
|
-
|
|
23
|
+
2.5.0
|
|
24
|
+
|
|
25
|
+
---
|
|
18
26
|
|
|
19
27
|
- Support click captcha image to refresh new one by default.
|
|
20
28
|
- Use simple tag helper generate captcha img html, for avoid asset_host (#73).
|
|
21
29
|
|
|
22
|
-
2.4.0
|
|
23
|
-
|
|
30
|
+
2.4.0
|
|
31
|
+
|
|
32
|
+
---
|
|
24
33
|
|
|
25
34
|
- Add skip_cache_store_check configuration. (#63)
|
|
26
35
|
- Fix for generate captcha with relative path, not url. (#58)
|
|
27
36
|
|
|
28
|
-
2.3.2
|
|
29
|
-
|
|
37
|
+
2.3.2
|
|
38
|
+
|
|
39
|
+
---
|
|
30
40
|
|
|
31
41
|
- Change Yellow and Green colors to Pink and Deep Purple to pass WCAG 2.0's contrast test. (#70)
|
|
32
42
|
|
|
33
|
-
2.3.1
|
|
34
|
-
|
|
43
|
+
2.3.1
|
|
44
|
+
|
|
45
|
+
---
|
|
35
46
|
|
|
36
47
|
- Fix #67 a y chars will invalid error (only in 2.3.0).
|
|
37
48
|
|
|
38
|
-
2.3.0
|
|
39
|
-
|
|
49
|
+
2.3.0
|
|
50
|
+
|
|
51
|
+
---
|
|
40
52
|
|
|
41
53
|
- Add `config.outline` for use outline style.
|
|
42
54
|
- Reduce colors down to 5 (red, blue, green, yellow and black).
|
|
43
55
|
|
|
44
|
-
2.2.0
|
|
45
|
-
|
|
56
|
+
2.2.0
|
|
57
|
+
|
|
58
|
+
---
|
|
46
59
|
|
|
47
60
|
- Add option `config.length` for support change number chars. (#57)
|
|
48
61
|
- Add option `config.strikethrough` for enable or disable strikethrough. (#57)
|
|
49
62
|
|
|
50
|
-
2.1.3
|
|
51
|
-
|
|
63
|
+
2.1.3
|
|
64
|
+
|
|
65
|
+
---
|
|
52
66
|
|
|
53
67
|
- Windows support fixed with `send_data` method. (#45)
|
|
54
68
|
|
|
55
|
-
2.1.2
|
|
56
|
-
|
|
69
|
+
2.1.2
|
|
70
|
+
|
|
71
|
+
---
|
|
57
72
|
|
|
58
73
|
- Do not change captcha when `HEAD /rucaptcha`.
|
|
59
74
|
|
|
60
|
-
2.1.1
|
|
61
|
-
|
|
75
|
+
2.1.1
|
|
76
|
+
|
|
77
|
+
---
|
|
62
78
|
|
|
63
79
|
- Mount engine use `prepend` method to get high priority in config/routes.rb.
|
|
64
80
|
|
|
65
|
-
2.1.0
|
|
66
|
-
|
|
81
|
+
2.1.0
|
|
82
|
+
|
|
83
|
+
---
|
|
67
84
|
|
|
68
85
|
- Mount Router by default, not need config now.
|
|
69
86
|
|
|
70
87
|
> IMPORTANT: Wen you upgrade this version, you need remove `mount RuCaptcha::Engine` line from your `config/routes.rb`
|
|
88
|
+
|
|
71
89
|
- Default use [:file_store, 'tmp/cache/rucaptcha/session'] as RuCaptcha.config.cache_store, now it can work without any configurations.
|
|
72
90
|
|
|
73
91
|
> NOTE: But you still need care about `config.cache_store` to setup on a right way.
|
|
74
92
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
2.0.3
|
|
78
|
-
-----
|
|
93
|
+
## 2.0.3
|
|
79
94
|
|
|
80
95
|
- Use `ActiveSupport.on_load` to extend ActionController and ActionView.
|
|
81
96
|
|
|
82
|
-
2.0.1
|
|
83
|
-
|
|
97
|
+
2.0.1
|
|
98
|
+
|
|
99
|
+
---
|
|
84
100
|
|
|
85
101
|
- Fix `/rucaptcha` path issue when `config.action_controller.asset_host` has setup with CDN url.
|
|
86
102
|
|
|
87
|
-
2.0.0
|
|
88
|
-
|
|
103
|
+
2.0.0
|
|
104
|
+
|
|
105
|
+
---
|
|
89
106
|
|
|
90
|
-
|
|
107
|
+
_Break Changes!_
|
|
91
108
|
|
|
92
109
|
WARNING!: This version have so many break changes!
|
|
93
110
|
|
|
@@ -96,29 +113,34 @@ WARNING!: This version have so many break changes!
|
|
|
96
113
|
- Remove `len`, `font_size`, `cache_limit` config key, no support now.
|
|
97
114
|
- Output `GIF` format.
|
|
98
115
|
|
|
99
|
-
1.2.0
|
|
100
|
-
|
|
116
|
+
1.2.0
|
|
117
|
+
|
|
118
|
+
---
|
|
101
119
|
|
|
102
120
|
- Add an `:keep_session` option for `verify_rucaptcha?` method to giva a way for let you keep session on verify, if true, RuCaptcha will not delete the captcha code session after validation.
|
|
103
121
|
|
|
104
|
-
1.1.4
|
|
105
|
-
|
|
122
|
+
1.1.4
|
|
123
|
+
|
|
124
|
+
---
|
|
106
125
|
|
|
107
126
|
- Fix #35 just give a warning message if not setup a right cache_store, only raise on :null_store.
|
|
108
127
|
|
|
109
|
-
1.1.2
|
|
110
|
-
|
|
128
|
+
1.1.2
|
|
129
|
+
|
|
130
|
+
---
|
|
111
131
|
|
|
112
132
|
- Fix #34 rucaptcha.root_url -> root_path, to avoid generate a http url in a https application.
|
|
113
133
|
- Fix spec to require Ruby 2.0.0, because there have a `Module#prepend` method called.
|
|
114
134
|
|
|
115
|
-
1.1.1
|
|
116
|
-
|
|
135
|
+
1.1.1
|
|
136
|
+
|
|
137
|
+
---
|
|
117
138
|
|
|
118
139
|
- Remove inspect log on verify_rucaptcha
|
|
119
140
|
|
|
120
|
-
1.1.0
|
|
121
|
-
|
|
141
|
+
1.1.0
|
|
142
|
+
|
|
143
|
+
---
|
|
122
144
|
|
|
123
145
|
- Add `cache_store` config key to setup a cache store location for RuCaptcha.
|
|
124
146
|
- Store captcha in custom cache store.
|
|
@@ -127,116 +149,136 @@ WARNING!: This version have so many break changes!
|
|
|
127
149
|
|
|
128
150
|
- Fix Session replay secure issue that when Rails application use CookieStore.
|
|
129
151
|
|
|
130
|
-
1.0.0
|
|
131
|
-
|
|
152
|
+
1.0.0
|
|
153
|
+
|
|
154
|
+
---
|
|
132
155
|
|
|
133
156
|
- Adjust to avoid lighter colors.
|
|
134
157
|
- Avoid continuous chars have same color.
|
|
135
158
|
- Use same color for each chars in :black_white mode.
|
|
136
159
|
|
|
137
|
-
0.5.1
|
|
138
|
-
|
|
160
|
+
0.5.1
|
|
161
|
+
|
|
162
|
+
---
|
|
139
163
|
|
|
140
164
|
- Make sure it will render image when ImageMagick stderr have warning messages. (#26)
|
|
141
165
|
|
|
142
|
-
0.5.0
|
|
143
|
-
|
|
166
|
+
0.5.0
|
|
167
|
+
|
|
168
|
+
---
|
|
144
169
|
|
|
145
170
|
- Fix cache with Rails 5.
|
|
146
171
|
|
|
147
|
-
0.4.5
|
|
148
|
-
|
|
172
|
+
0.4.5
|
|
173
|
+
|
|
174
|
+
---
|
|
149
175
|
|
|
150
176
|
- Removed `posix-spawn` dependency, used open3 instead (core funciontality), JRuby compatible (#24)
|
|
151
177
|
|
|
152
|
-
0.4.4
|
|
153
|
-
|
|
178
|
+
0.4.4
|
|
179
|
+
|
|
180
|
+
---
|
|
154
181
|
|
|
155
182
|
- Remove deprecated `width`, `height` config.
|
|
156
183
|
- Delete session key after verify (#23).
|
|
157
184
|
- Lighter text color, improve style.
|
|
158
185
|
|
|
159
|
-
0.4.2
|
|
160
|
-
|
|
186
|
+
0.4.2
|
|
187
|
+
|
|
188
|
+
---
|
|
161
189
|
|
|
162
190
|
- Fix NoMethodError bug when params[:_rucaptha] is nil.
|
|
163
191
|
|
|
164
|
-
0.4.1
|
|
165
|
-
|
|
192
|
+
0.4.1
|
|
193
|
+
|
|
194
|
+
---
|
|
166
195
|
|
|
167
196
|
- Add error message to resource when captcha code expired.
|
|
168
197
|
|
|
169
|
-
0.4.0
|
|
170
|
-
|
|
198
|
+
0.4.0
|
|
199
|
+
|
|
200
|
+
---
|
|
171
201
|
|
|
172
202
|
- Add `config.colorize` option, to allow use black text theme.
|
|
173
203
|
|
|
174
|
-
0.3.3
|
|
175
|
-
|
|
204
|
+
0.3.3
|
|
205
|
+
|
|
206
|
+
---
|
|
176
207
|
|
|
177
208
|
- Add `config.expires_in` to allow change captcha code expire time.
|
|
178
209
|
|
|
179
|
-
0.3.2.1
|
|
180
|
-
|
|
210
|
+
0.3.2.1
|
|
211
|
+
|
|
212
|
+
---
|
|
181
213
|
|
|
182
214
|
- Add Windows development env support.
|
|
183
215
|
|
|
184
|
-
0.3.2
|
|
185
|
-
|
|
216
|
+
0.3.2
|
|
217
|
+
|
|
218
|
+
---
|
|
186
219
|
|
|
187
220
|
- Make better render positions;
|
|
188
221
|
- Trim blank space.
|
|
189
222
|
|
|
190
|
-
0.3.1
|
|
191
|
-
|
|
223
|
+
0.3.1
|
|
224
|
+
|
|
225
|
+
---
|
|
192
226
|
|
|
193
227
|
- More complex Image render: compact text, strong lines, +/-5 rotate...
|
|
194
228
|
- [DEPRECATION] config.width, config.height removed, use config.font_size.
|
|
195
229
|
- Fix the render position in difference font sizes.
|
|
196
230
|
- Fix input field type, and disable autocorrect, autocapitalize, and limit maxlength with char length;
|
|
197
231
|
|
|
198
|
-
0.2.5
|
|
199
|
-
|
|
232
|
+
0.2.5
|
|
233
|
+
|
|
234
|
+
---
|
|
200
235
|
|
|
201
236
|
- Add `session[:_rucaptcha]` expire time, for protect Rails CookieSession Replay Attack.
|
|
202
237
|
- Captcha input field disable autocomplete, and set field type as `email` for shown correct keyboard on mobile view.
|
|
203
238
|
|
|
204
|
-
0.2.3
|
|
205
|
-
|
|
239
|
+
0.2.3
|
|
240
|
+
|
|
241
|
+
---
|
|
206
242
|
|
|
207
243
|
- It will raise error when call ImageMagick failed.
|
|
208
244
|
|
|
209
|
-
0.2.2
|
|
210
|
-
|
|
245
|
+
0.2.2
|
|
246
|
+
|
|
247
|
+
---
|
|
211
248
|
|
|
212
249
|
- Added locale for pt-BR language; @ramirovjr
|
|
213
250
|
|
|
214
|
-
0.2.1
|
|
215
|
-
|
|
251
|
+
0.2.1
|
|
252
|
+
|
|
253
|
+
---
|
|
216
254
|
|
|
217
255
|
- Fix issue when cache dir not exist.
|
|
218
256
|
|
|
219
|
-
0.2.0
|
|
220
|
-
|
|
257
|
+
0.2.0
|
|
258
|
+
|
|
259
|
+
---
|
|
221
260
|
|
|
222
261
|
- Added file cache, can setup how many images you want generate by `config.cache_limit`,
|
|
223
262
|
RuCaptcha will use cache for next requests.
|
|
224
263
|
When you restart Rails processes it will generate new again and clean the old caches.
|
|
225
264
|
|
|
226
|
-
0.1.4
|
|
227
|
-
|
|
265
|
+
0.1.4
|
|
266
|
+
|
|
267
|
+
---
|
|
228
268
|
|
|
229
269
|
- Fix `verify_rucaptcha?` logic in somecase.
|
|
230
270
|
- Locales fixed.
|
|
231
271
|
|
|
232
|
-
0.1.3
|
|
233
|
-
|
|
272
|
+
0.1.3
|
|
273
|
+
|
|
274
|
+
---
|
|
234
275
|
|
|
235
276
|
- `zh-TW` translate file fixed.
|
|
236
277
|
- Use xxx_url to fix bad captcha URL for `config.action_controller.asset_host` enabled case.
|
|
237
278
|
|
|
238
|
-
0.1.2
|
|
239
|
-
|
|
279
|
+
0.1.2
|
|
280
|
+
|
|
281
|
+
---
|
|
240
282
|
|
|
241
283
|
- No case sensitive;
|
|
242
284
|
- Export config.implode;
|
|
@@ -244,12 +286,14 @@ WARNING!: This version have so many break changes!
|
|
|
244
286
|
- Don't generate chars in 'l,o,0,1'.
|
|
245
287
|
- Render lower case chars on image.
|
|
246
288
|
|
|
247
|
-
0.1.1
|
|
248
|
-
|
|
289
|
+
0.1.1
|
|
290
|
+
|
|
291
|
+
---
|
|
249
292
|
|
|
250
293
|
- Include default validation I18n messages (en, zh-CN, zh-TW).
|
|
251
294
|
|
|
252
|
-
0.1.0
|
|
253
|
-
|
|
295
|
+
0.1.0
|
|
296
|
+
|
|
297
|
+
---
|
|
254
298
|
|
|
255
299
|
- First release.
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# RuCaptcha
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/rucaptcha)
|
|
4
|
-
[](https://github.com/huacnlee/rucaptcha/actions?query=workflow%3Abuild)
|
|
5
5
|
|
|
6
6
|
This is a Captcha gem for Rails Applications which generates captcha image by C code.
|
|
7
7
|
|
|
@@ -64,6 +64,7 @@ RuCaptcha 没有使用 Rails Session 来存储验证码信息,因为 Rails 的
|
|
|
64
64
|
所以,我建议大家使用的时候,配置上 `cache_store` (详见 [Rails Guides 缓存配置部分](https://ruby-china.github.io/rails-guides/caching_with_rails.html#%E9%85%8D%E7%BD%AE)的文档)到一个 Memcached 或 Redis,这才是最佳实践。
|
|
65
65
|
|
|
66
66
|
#
|
|
67
|
+
|
|
67
68
|
(RuCaptha do not use Rails Session to store captcha information. As the default session is stored in Cookie in Rails, there's a [Replay attack](https://en.wikipedia.org/wiki/Replay_attack) bug which may causes capthcha being destroyed if we store captcha in Rails Session.
|
|
68
69
|
|
|
69
70
|
So in my design I require RuCaptcha to configure a distributed backend storage scheme, such as Memcached, Redis or other cache_store schemes which support distribution.
|
|
@@ -2,10 +2,11 @@ module RuCaptcha
|
|
|
2
2
|
class CaptchaController < ActionController::Base
|
|
3
3
|
def index
|
|
4
4
|
return head :ok if request.head?
|
|
5
|
-
|
|
6
|
-
headers[
|
|
5
|
+
|
|
6
|
+
headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
|
7
|
+
headers["Pragma"] = "no-cache"
|
|
7
8
|
data = generate_rucaptcha
|
|
8
|
-
opts = { disposition:
|
|
9
|
+
opts = { disposition: "inline", type: "image/gif" }
|
|
9
10
|
send_data data, opts
|
|
10
11
|
end
|
|
11
12
|
end
|
data/config/routes.rb
CHANGED
data/ext/rucaptcha/extconf.rb
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require
|
|
2
|
-
create_makefile(
|
|
1
|
+
require "mkmf"
|
|
2
|
+
create_makefile("rucaptcha/rucaptcha")
|
data/lib/rucaptcha.rb
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
1
|
+
require "rails"
|
|
2
|
+
require "action_controller"
|
|
3
|
+
require "active_support/all"
|
|
4
|
+
require "rucaptcha/rucaptcha"
|
|
5
|
+
require "rucaptcha/version"
|
|
6
|
+
require "rucaptcha/configuration"
|
|
7
|
+
require "rucaptcha/controller_helpers"
|
|
8
|
+
require "rucaptcha/view_helpers"
|
|
9
|
+
require "rucaptcha/cache"
|
|
10
|
+
require "rucaptcha/engine"
|
|
11
|
+
require "rucaptcha/errors/configuration"
|
|
12
12
|
|
|
13
13
|
module RuCaptcha
|
|
14
14
|
class << self
|
|
15
15
|
def config
|
|
16
16
|
return @config if defined?(@config)
|
|
17
|
+
|
|
17
18
|
@config = Configuration.new
|
|
18
19
|
@config.style = :colorful
|
|
19
20
|
@config.length = 5
|
|
@@ -22,11 +23,11 @@ module RuCaptcha
|
|
|
22
23
|
@config.expires_in = 2.minutes
|
|
23
24
|
@config.skip_cache_store_check = false
|
|
24
25
|
|
|
25
|
-
if Rails.application
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
@config.cache_store = if Rails.application
|
|
27
|
+
Rails.application.config.cache_store
|
|
28
|
+
else
|
|
29
|
+
:mem_cache_store
|
|
30
|
+
end
|
|
30
31
|
@config.cache_store
|
|
31
32
|
@config
|
|
32
33
|
end
|
|
@@ -35,24 +36,22 @@ module RuCaptcha
|
|
|
35
36
|
config.instance_exec(&block)
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
def generate
|
|
39
|
+
def generate
|
|
39
40
|
style = config.style == :colorful ? 1 : 0
|
|
40
41
|
length = config.length
|
|
41
42
|
|
|
42
|
-
unless length.in?(3..7)
|
|
43
|
-
raise RuCaptcha::Errors::Configuration, 'length config error, value must in 3..7'
|
|
44
|
-
end
|
|
43
|
+
raise RuCaptcha::Errors::Configuration, "length config error, value must in 3..7" unless length.in?(3..7)
|
|
45
44
|
|
|
46
45
|
strikethrough = config.strikethrough ? 1 : 0
|
|
47
46
|
outline = config.outline ? 1 : 0
|
|
48
|
-
|
|
47
|
+
create(style, length, strikethrough, outline)
|
|
49
48
|
end
|
|
50
49
|
|
|
51
50
|
def check_cache_store!
|
|
52
51
|
cache_store = RuCaptcha.config.cache_store
|
|
53
52
|
store_name = cache_store.is_a?(Array) ? cache_store.first : cache_store
|
|
54
|
-
if [
|
|
55
|
-
RuCaptcha.config.cache_store = [:file_store, Rails.root.join(
|
|
53
|
+
if %i[memory_store null_store file_store].include?(store_name)
|
|
54
|
+
RuCaptcha.config.cache_store = [:file_store, Rails.root.join("tmp/cache/rucaptcha/session")]
|
|
56
55
|
|
|
57
56
|
puts "
|
|
58
57
|
|
|
@@ -72,7 +71,7 @@ module RuCaptcha
|
|
|
72
71
|
end
|
|
73
72
|
|
|
74
73
|
ActiveSupport.on_load(:action_controller) do
|
|
75
|
-
ActionController::Base.
|
|
74
|
+
ActionController::Base.include RuCaptcha::ControllerHelpers
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
ActiveSupport.on_load(:action_view) do
|
data/lib/rucaptcha/cache.rb
CHANGED
|
@@ -8,19 +8,18 @@ module RuCaptcha
|
|
|
8
8
|
|
|
9
9
|
# session key of rucaptcha
|
|
10
10
|
def rucaptcha_sesion_key_key
|
|
11
|
-
|
|
12
11
|
session_id = session.respond_to?(:id) ? session.id : session[:session_id]
|
|
13
12
|
warning_when_session_invalid if session_id.blank?
|
|
14
13
|
|
|
15
14
|
# With https://github.com/rack/rack/commit/7fecaee81f59926b6e1913511c90650e76673b38
|
|
16
15
|
# to protected session_id into secret
|
|
17
16
|
session_id_digest = Digest::SHA256.hexdigest(session_id.inspect)
|
|
18
|
-
[
|
|
17
|
+
["rucaptcha-session", session_id_digest].join(":")
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
# Generate a new Captcha
|
|
22
21
|
def generate_rucaptcha
|
|
23
|
-
res = RuCaptcha.generate
|
|
22
|
+
res = RuCaptcha.generate
|
|
24
23
|
session_val = {
|
|
25
24
|
code: res[0],
|
|
26
25
|
time: Time.now.to_i
|
|
@@ -44,7 +43,7 @@ module RuCaptcha
|
|
|
44
43
|
# verify_rucaptcha?(nil, keep_session: true)
|
|
45
44
|
# verify_rucaptcha?(nil, captcha: params[:user][:captcha])
|
|
46
45
|
#
|
|
47
|
-
def verify_rucaptcha?(
|
|
46
|
+
def verify_rucaptcha?(_resource = nil, opts = {})
|
|
48
47
|
opts ||= {}
|
|
49
48
|
|
|
50
49
|
store_info = RuCaptcha.cache.read(rucaptcha_sesion_key_key)
|
|
@@ -52,24 +51,16 @@ module RuCaptcha
|
|
|
52
51
|
RuCaptcha.cache.delete(rucaptcha_sesion_key_key) unless opts[:keep_session]
|
|
53
52
|
|
|
54
53
|
# Make sure session exist
|
|
55
|
-
if store_info.blank?
|
|
56
|
-
return add_rucaptcha_validation_error
|
|
57
|
-
end
|
|
54
|
+
return add_rucaptcha_validation_error if store_info.blank?
|
|
58
55
|
|
|
59
56
|
# Make sure not expire
|
|
60
|
-
if (Time.now.to_i - store_info[:time]) > RuCaptcha.config.expires_in
|
|
61
|
-
return add_rucaptcha_validation_error
|
|
62
|
-
end
|
|
57
|
+
return add_rucaptcha_validation_error if (Time.now.to_i - store_info[:time]) > RuCaptcha.config.expires_in
|
|
63
58
|
|
|
64
59
|
# Make sure parama have captcha
|
|
65
|
-
captcha = (opts[:captcha] || params[:_rucaptcha] ||
|
|
66
|
-
if captcha.blank?
|
|
67
|
-
return add_rucaptcha_validation_error
|
|
68
|
-
end
|
|
60
|
+
captcha = (opts[:captcha] || params[:_rucaptcha] || "").downcase.strip
|
|
61
|
+
return add_rucaptcha_validation_error if captcha.blank?
|
|
69
62
|
|
|
70
|
-
if captcha != store_info[:code]
|
|
71
|
-
return add_rucaptcha_validation_error
|
|
72
|
-
end
|
|
63
|
+
return add_rucaptcha_validation_error if captcha != store_info[:code]
|
|
73
64
|
|
|
74
65
|
true
|
|
75
66
|
end
|
|
@@ -78,7 +69,7 @@ module RuCaptcha
|
|
|
78
69
|
|
|
79
70
|
def add_rucaptcha_validation_error
|
|
80
71
|
if defined?(resource) && resource && resource.respond_to?(:errors)
|
|
81
|
-
resource.errors.add(:base, t(
|
|
72
|
+
resource.errors.add(:base, t("rucaptcha.invalid"))
|
|
82
73
|
end
|
|
83
74
|
false
|
|
84
75
|
end
|
data/lib/rucaptcha/engine.rb
CHANGED
|
@@ -2,11 +2,11 @@ module RuCaptcha
|
|
|
2
2
|
class Engine < ::Rails::Engine
|
|
3
3
|
isolate_namespace RuCaptcha
|
|
4
4
|
|
|
5
|
-
initializer
|
|
5
|
+
initializer "rucaptcha.init" do |app|
|
|
6
6
|
# https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_dispatch/routing/route_set.rb#L268
|
|
7
7
|
# `app.routes.prepend` start from Rails 3.2 - 5.0
|
|
8
8
|
app.routes.prepend do
|
|
9
|
-
mount RuCaptcha::Engine =>
|
|
9
|
+
mount RuCaptcha::Engine => "/rucaptcha"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
RuCaptcha.check_cache_store! unless RuCaptcha.config.skip_cache_store_check
|
data/lib/rucaptcha/version.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
module RuCaptcha
|
|
2
2
|
module ViewHelpers
|
|
3
3
|
def rucaptcha_input_tag(opts = {})
|
|
4
|
-
opts[:name] =
|
|
5
|
-
opts[:type] =
|
|
6
|
-
opts[:autocorrect] =
|
|
7
|
-
opts[:autocapitalize] =
|
|
8
|
-
opts[:pattern] =
|
|
9
|
-
opts[:autocomplete] =
|
|
10
|
-
opts[:maxlength]
|
|
4
|
+
opts[:name] = "_rucaptcha"
|
|
5
|
+
opts[:type] = "text"
|
|
6
|
+
opts[:autocorrect] = "off"
|
|
7
|
+
opts[:autocapitalize] = "off"
|
|
8
|
+
opts[:pattern] = "[a-zA-Z]*"
|
|
9
|
+
opts[:autocomplete] = "off"
|
|
10
|
+
opts[:maxlength] = RuCaptcha.config.length
|
|
11
11
|
tag(:input, opts)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def rucaptcha_image_tag(opts = {})
|
|
15
|
-
opts[:class] = opts[:class] ||
|
|
15
|
+
opts[:class] = opts[:class] || "rucaptcha-image"
|
|
16
16
|
opts[:src] = ru_captcha.root_path
|
|
17
17
|
opts[:onclick] = "this.src = '#{ru_captcha.root_path}?t=' + Date.now();"
|
|
18
18
|
tag(:img, opts)
|
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.5.
|
|
4
|
+
version: 2.5.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Lee
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: railties
|
|
@@ -38,7 +38,7 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '1'
|
|
41
|
-
description:
|
|
41
|
+
description:
|
|
42
42
|
email: huacnlee@gmail.com
|
|
43
43
|
executables: []
|
|
44
44
|
extensions:
|
|
@@ -69,7 +69,7 @@ homepage: https://github.com/huacnlee/rucaptcha
|
|
|
69
69
|
licenses:
|
|
70
70
|
- MIT
|
|
71
71
|
metadata: {}
|
|
72
|
-
post_install_message:
|
|
72
|
+
post_install_message:
|
|
73
73
|
rdoc_options: []
|
|
74
74
|
require_paths:
|
|
75
75
|
- lib
|
|
@@ -84,8 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
84
84
|
- !ruby/object:Gem::Version
|
|
85
85
|
version: '0'
|
|
86
86
|
requirements: []
|
|
87
|
-
rubygems_version: 3.
|
|
88
|
-
signing_key:
|
|
87
|
+
rubygems_version: 3.1.4
|
|
88
|
+
signing_key:
|
|
89
89
|
specification_version: 4
|
|
90
90
|
summary: This is a Captcha gem for Rails Applications. It drawing captcha image with
|
|
91
91
|
C code so it no dependencies.
|