blogs_captcha 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cad6c7ee8510b81815207edbc73233be18c0853561396fee03b32a3f043ddd16
4
- data.tar.gz: 0df555738484700779c4ac944a1d141cfe62252ce28274994580964f4f38d28e
3
+ metadata.gz: 57bc75ea05cf9b30bf5985c974b3b2f2c6365d4db0a55beb97ca5cbbc585f5a4
4
+ data.tar.gz: 21dfa9deeca2067ad4533f4fe00be2e03bf858c6934e617a6d5e6349590daca9
5
5
  SHA512:
6
- metadata.gz: 295d60917fb5c2b690061ff82972d274cf0e61425870963bd27ce27b00d0c590575eed37130af02194e7ee1606728d8f73cf7a4817b35cc4b8e8f8f918209ca2
7
- data.tar.gz: 7d30bf6af0232290ee1bf05ff6761408253343b3e3da46a8f45c24b882795e0a5a039225fe9bd408f7b97905a64366b9ea30a63e37eac2246486801fb7f04353
6
+ metadata.gz: 789ccb60f7d0764450bcd67bcf509f19ea844f37e7e956f21c8921e50c0169a04dd6476edff91bbec641994d15c98b46cc38151fc4bd7c0e81b7844599405fb0
7
+ data.tar.gz: d76b2fdd259e9728a4304fa952ed25d361f79fdd3a4dfd20da9b467f0beb347a891f0a8870fbfbab6fd9fc7bfcd51ccc06f738cb91fa1efa56375d750e92c737
@@ -4,7 +4,7 @@ module BlogsCaptcha
4
4
  return head :ok if request.head?
5
5
  headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
6
6
  headers['Pragma'] = 'no-cache'
7
- data = generate_rucaptcha
7
+ data = generate_captcha
8
8
  opts = { disposition: 'inline', type: 'image/gif' }
9
9
  send_data data, opts
10
10
  end
@@ -3,86 +3,35 @@ module BlogsCaptcha
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- helper_method :verify_rucaptcha?
6
+ helper_method :verify_captcha?
7
7
  end
8
8
 
9
- # session key of rucaptcha
10
- def rucaptcha_sesion_key_key
11
- session_id = session.respond_to?(:id) ? session.id : session[:session_id]
12
- warning_when_session_invalid if session_id.blank?
13
- ['rucaptcha-session', session_id].join(':')
9
+ def captcha_sesion_key_key
10
+ ['captcha-session', 'test'].join(':')
14
11
  end
15
12
 
16
13
  # Generate a new Captcha
17
- def generate_rucaptcha
14
+ def generate_captcha
18
15
  res = BlogsCaptcha.generate()
19
16
  session_val = {
20
17
  code: res[0],
21
18
  time: Time.now.to_i
22
19
  }
23
- RuCaptcha.cache.write(rucaptcha_sesion_key_key, session_val, expires_in: RuCaptcha.config.expires_in)
20
+ BlogsCaptcha.cache.write(captcha_sesion_key_key, session_val, expires_in: BlogsCaptcha.config.expires_in)
24
21
  res[1]
25
22
  end
26
23
 
27
- # Verify captcha code
28
- #
29
- # params:
30
- # resource - [optional] a ActiveModel object, if given will add validation error message to object.
31
- # :keep_session - if true, RuCaptcha will not delete the captcha code session.
32
- # :captcha - if given, the value of it will be used to verify the captcha,
33
- # if do not give or blank, the value of params[:_rucaptcha] will be used to verify the captcha
34
- #
35
- # exmaples:
36
- #
37
- # verify_rucaptcha?
38
- # verify_rucaptcha?(user, keep_session: true)
39
- # verify_rucaptcha?(nil, keep_session: true)
40
- # verify_rucaptcha?(nil, captcha: params[:user][:captcha])
41
- #
42
- def verify_rucaptcha?(resource = nil, opts = {})
43
- opts ||= {}
44
-
45
- store_info = BlogsCaptcha.cache.read(rucaptcha_sesion_key_key)
46
- # make sure move used key
47
- BlogsCaptcha.cache.delete(rucaptcha_sesion_key_key) unless opts[:keep_session]
48
-
49
- # Make sure session exist
50
- if store_info.blank?
51
- return add_rucaptcha_validation_error
52
- end
53
-
54
- # Make sure not expire
55
- if (Time.now.to_i - store_info[:time]) > BlogsCaptcha.config.expires_in
56
- return add_rucaptcha_validation_error
57
- end
58
-
59
- # Make sure parama have captcha
60
- captcha = (opts[:captcha] || params[:_rucaptcha] || '').downcase.strip
61
- if captcha.blank?
62
- return add_rucaptcha_validation_error
63
- end
64
-
65
- if captcha != store_info[:code]
66
- return add_rucaptcha_validation_error
67
- end
68
-
69
- true
24
+ def verify_captcha?(resource = nil, opts = {})
25
+ #TODO
70
26
  end
71
27
 
72
28
  private
73
29
 
74
- def add_rucaptcha_validation_error
30
+ def add_captcha_validation_error
75
31
  if defined?(resource) && resource && resource.respond_to?(:errors)
76
- resource.errors.add(:base, t('rucaptcha.invalid'))
32
+ resource.errors.add(:base, t('captcha.invalid'))
77
33
  end
78
34
  false
79
35
  end
80
-
81
- def warning_when_session_invalid
82
- Rails.logger.warn "
83
- WARNING! The session.id is blank, RuCaptcha can't work properly, please keep session available.
84
- More details about this: https://github.com/huacnlee/rucaptcha/pull/66
85
- "
86
- end
87
36
  end
88
37
  end
@@ -1,3 +1,3 @@
1
1
  module BlogsCaptcha
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blogs_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChinaHDJ