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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a80c7408ad417d8f3fea20f1d934334f37de3289fc90165d16f23b3c84715d13
4
- data.tar.gz: f1d66f613aee6a35590db8ead09bb92cebe8bb75e44f371c80290eeaf2e3597d
3
+ metadata.gz: 44a2c6f49f4b55bcb3c88f3fc6f0e6693f61fee8d392a6cedb921524641bd5e9
4
+ data.tar.gz: 5620531b8a5e2924a87a751f6a282360f410342ca3d1f87dc7021a4ba3c83571
5
5
  SHA512:
6
- metadata.gz: 4ef9ca7b1aa9eef11426535e5c09e3ce64325e5674c691c1e3c2e87d42980c5ec1082262c2cd73c6ae6ba934f3919134709e8921a78de01517e2841cd5e1d3ac
7
- data.tar.gz: 22c419b540e631434119e0bc6903f4c564493d4154a7d805c9afa4b20dffb6193b9713fedbfc26e412adc5d0b78b23b7e45e1163638d2d1e2239f1f03966de40
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.1.0)
5
- activesupport (>= 5.0)
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.0.2.2)
10
+ activesupport (6.1.5)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 0.7, < 2)
13
- minitest (~> 5.1)
14
- tzinfo (~> 1.1)
15
- zeitwerk (~> 2.2)
16
- concurrent-ruby (1.1.6)
17
- i18n (1.8.2)
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.14.0)
19
+ minitest (5.15.0)
20
20
  rake (13.0.1)
21
21
  rake-compiler (1.1.0)
22
22
  rake
23
- thread_safe (0.3.6)
24
- tzinfo (1.2.7)
25
- thread_safe (~> 0.1)
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.0.1
35
+ 2.3.12
@@ -0,0 +1,12 @@
1
+ require "fileutils"
2
+
3
+ module RaCaptcha
4
+ class << self
5
+ def cache
6
+ return @cache if defined? @cache
7
+
8
+ @cache = ActiveSupport::Cache.lookup_store(RaCaptcha.config.cache_store)
9
+ @cache
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module RaCaptcha
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
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 = :colorful
14
- @config.length = 5
14
+ @config.style = :colorful
15
+ @config.length = 4
15
16
  @config.strikethrough = true
16
- @config.outline = false
17
- @config.expires_in = 2.minutes
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 setup(&block)
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 = RaCaptcha.generate
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: RaCaptcha.config.expires_in)
58
- res[1]
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]) > RaCaptcha.config.expires_in
72
+ return [false, "验证码已过期"] if (Time.now.to_i - store_info[:time]) > config.expires_in
81
73
 
82
74
  # Make sure have captcha
83
- captcha = (options[:captcha] || "").downcase.strip
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
@@ -38,6 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.required_ruby_version = ">= 2.0.0"
39
39
  spec.extensions = %w[ext/racaptcha/extconf.rb]
40
40
 
41
- spec.add_runtime_dependency 'activesupport', '>= 5.0'
42
41
  spec.add_development_dependency 'rake-compiler', '~> 1'
43
42
  end
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.2.1
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: 2021-08-16 00:00:00.000000000 Z
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
- rubyforge_project:
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.