racaptcha 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -15
- data/lib/racaptcha/cache.rb +12 -0
- data/lib/racaptcha/version.rb +1 -1
- data/lib/racaptcha.rb +17 -25
- data/racaptcha.gemspec +0 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44a2c6f49f4b55bcb3c88f3fc6f0e6693f61fee8d392a6cedb921524641bd5e9
|
4
|
+
data.tar.gz: 5620531b8a5e2924a87a751f6a282360f410342ca3d1f87dc7021a4ba3c83571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31273910d07ab1a8b9e54520072df00862e10a9707e7b0af0ea8b6a4c369e16ef7bca5f3f7fdaf590b838573cbf5d8d628d5b7f711263158a4c6df6606203599
|
7
|
+
data.tar.gz: e3ff4cc023e22b70aef4bf0e79f870b983f66e8729701db0cbca595368d92da5004c647a448bfbd6d297e035c0e349dd4af856c4671b3dc29d41de1d779e6fbe
|
data/Gemfile.lock
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
racaptcha (0.
|
5
|
-
activesupport (>= 5.
|
4
|
+
racaptcha (0.2.2)
|
5
|
+
activesupport (>= 5.2.4.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (6.
|
10
|
+
activesupport (6.1.5)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (>=
|
13
|
-
minitest (
|
14
|
-
tzinfo (~>
|
15
|
-
zeitwerk (~> 2.
|
16
|
-
concurrent-ruby (1.1.
|
17
|
-
i18n (1.
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
zeitwerk (~> 2.3)
|
16
|
+
concurrent-ruby (1.1.10)
|
17
|
+
i18n (1.10.0)
|
18
18
|
concurrent-ruby (~> 1.0)
|
19
|
-
minitest (5.
|
19
|
+
minitest (5.15.0)
|
20
20
|
rake (13.0.1)
|
21
21
|
rake-compiler (1.1.0)
|
22
22
|
rake
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
zeitwerk (2.3.0)
|
23
|
+
tzinfo (2.0.4)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
zeitwerk (2.5.4)
|
27
26
|
|
28
27
|
PLATFORMS
|
29
28
|
ruby
|
@@ -33,4 +32,4 @@ DEPENDENCIES
|
|
33
32
|
rake-compiler (~> 1)
|
34
33
|
|
35
34
|
BUNDLED WITH
|
36
|
-
2.
|
35
|
+
2.3.12
|
data/lib/racaptcha/version.rb
CHANGED
data/lib/racaptcha.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require "active_support/all"
|
2
|
-
require "racaptcha/racaptcha"
|
3
2
|
require "racaptcha/version"
|
4
3
|
require "racaptcha/configuration"
|
4
|
+
require "racaptcha/cache"
|
5
5
|
require "racaptcha/errors/configuration"
|
6
|
+
require "racaptcha/racaptcha"
|
6
7
|
|
7
8
|
module RaCaptcha
|
8
9
|
class << self
|
@@ -10,29 +11,19 @@ module RaCaptcha
|
|
10
11
|
return @config if defined?(@config)
|
11
12
|
|
12
13
|
@config = Configuration.new
|
13
|
-
@config.style
|
14
|
-
@config.length
|
14
|
+
@config.style = :colorful
|
15
|
+
@config.length = 4
|
15
16
|
@config.strikethrough = true
|
16
|
-
@config.outline
|
17
|
-
@config.expires_in
|
17
|
+
@config.outline = false
|
18
|
+
@config.expires_in = 2.minutes
|
18
19
|
@config.skip_cache_store_check = false
|
19
|
-
|
20
|
-
@config.cache_store = :file_store
|
21
|
-
@config.cache_store
|
22
20
|
@config
|
23
21
|
end
|
24
22
|
|
25
|
-
def
|
23
|
+
def configure(&block)
|
26
24
|
config.instance_exec(&block)
|
27
25
|
end
|
28
26
|
|
29
|
-
def cache
|
30
|
-
return @cache if defined? @cache
|
31
|
-
|
32
|
-
@cache = ActiveSupport::Cache.lookup_store(RaCaptcha.config.cache_store)
|
33
|
-
@cache
|
34
|
-
end
|
35
|
-
|
36
27
|
# generate new captcha without cache
|
37
28
|
def generate
|
38
29
|
style = config.style == :colorful ? 1 : 0
|
@@ -49,13 +40,14 @@ module RaCaptcha
|
|
49
40
|
|
50
41
|
# generate new captcha with cache
|
51
42
|
def generate_captcha(cache_key = nil)
|
52
|
-
res =
|
43
|
+
res = generate
|
53
44
|
_val = {
|
54
45
|
code: res[0],
|
55
46
|
time: Time.now.to_i
|
56
47
|
}
|
57
|
-
RaCaptcha.cache.write(generate_cache_key(cache_key), _val, expires_in:
|
58
|
-
|
48
|
+
RaCaptcha.cache.write(generate_cache_key(cache_key), _val, expires_in: config.expires_in)
|
49
|
+
# 验证码图片,验证码,缓存key
|
50
|
+
[res[1], res[0], cache_key]
|
59
51
|
end
|
60
52
|
|
61
53
|
# verify captcha
|
@@ -74,18 +66,18 @@ module RaCaptcha
|
|
74
66
|
RaCaptcha.cache.delete(_key) unless options[:keep_cache]
|
75
67
|
|
76
68
|
# Make sure session exist
|
77
|
-
return false if store_info.blank?
|
69
|
+
return [false, "未找到存储的验证码"] if store_info.blank?
|
78
70
|
|
79
71
|
# Make sure not expire
|
80
|
-
return false if (Time.now.to_i - store_info[:time]) >
|
72
|
+
return [false, "验证码已过期"] if (Time.now.to_i - store_info[:time]) > config.expires_in
|
81
73
|
|
82
74
|
# Make sure have captcha
|
83
|
-
captcha =
|
84
|
-
return false if captcha.blank?
|
75
|
+
captcha = options[:captcha].to_s.downcase.strip
|
76
|
+
return [false, "请传递用户输入的验证码"] if captcha.blank?
|
85
77
|
|
86
|
-
return false if captcha != store_info[:code]
|
78
|
+
return [false, "验证码无效"] if captcha != store_info[:code]
|
87
79
|
|
88
|
-
true
|
80
|
+
return [true, "验证码正确"]
|
89
81
|
end
|
90
82
|
|
91
83
|
private
|
data/racaptcha.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: racaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wangrui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '5.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '5.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake-compiler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +48,7 @@ files:
|
|
62
48
|
- ext/racaptcha/font.h
|
63
49
|
- ext/racaptcha/racaptcha.c
|
64
50
|
- lib/racaptcha.rb
|
51
|
+
- lib/racaptcha/cache.rb
|
65
52
|
- lib/racaptcha/configuration.rb
|
66
53
|
- lib/racaptcha/errors/configuration.rb
|
67
54
|
- lib/racaptcha/version.rb
|
@@ -89,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
76
|
- !ruby/object:Gem::Version
|
90
77
|
version: '0'
|
91
78
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.7.11
|
79
|
+
rubygems_version: 3.0.3
|
94
80
|
signing_key:
|
95
81
|
specification_version: 4
|
96
82
|
summary: This is a Captcha gem for ruby.
|