rucaptcha 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/lib/rucaptcha/configuration.rb +1 -1
- data/lib/rucaptcha/controller_helpers.rb +39 -12
- data/lib/rucaptcha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eeac0b904fbb23ad981f2a15be405045dd3ab36
|
4
|
+
data.tar.gz: 509df17c96e7b4c5e9a16d780a0140a57496c342
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee75335b1a9494f3180976808f7f6bf15722c4d3fac3bf1ccccc58f519f81fac797cc3460a034ae58dc8c0dd5a825a4b86346c1f1802407a031ecd6187d201f4
|
7
|
+
data.tar.gz: 01dc3cf718968f2823f168f368bff69e2df8c056d5de7d285de44bd7284f449d191c98582425c9e550d8837cc3b58b53b9e1b7a6dc088659b65c1a1f8883c36e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ module RuCaptcha
|
|
11
11
|
attr_accessor :cache_limit
|
12
12
|
# Color style, default: :colorful, allows: [:colorful, :black_white]
|
13
13
|
attr_accessor :style
|
14
|
-
#
|
14
|
+
# rucaptcha expire time, default 2 minutes
|
15
15
|
attr_accessor :expires_in
|
16
16
|
end
|
17
17
|
end
|
@@ -6,28 +6,55 @@ module RuCaptcha
|
|
6
6
|
helper_method :verify_rucaptcha?
|
7
7
|
end
|
8
8
|
|
9
|
+
def rucaptcha_sesion_key_key
|
10
|
+
['rucaptcha-session', session.id].join(':')
|
11
|
+
end
|
12
|
+
|
9
13
|
def generate_rucaptcha
|
10
|
-
|
11
|
-
|
14
|
+
code = RuCaptcha::Captcha.random_chars
|
15
|
+
Rails.cache.write(rucaptcha_sesion_key_key, {
|
16
|
+
code: code,
|
17
|
+
time: Time.now.to_i
|
18
|
+
})
|
12
19
|
|
13
|
-
RuCaptcha::Captcha.create(
|
20
|
+
RuCaptcha::Captcha.create(code)
|
14
21
|
end
|
15
22
|
|
16
23
|
def verify_rucaptcha?(resource = nil)
|
17
|
-
|
18
|
-
|
24
|
+
store_info = Rails.cache.read(rucaptcha_sesion_key_key)
|
25
|
+
# make sure move used key
|
26
|
+
Rails.cache.delete(rucaptcha_sesion_key_key)
|
27
|
+
|
28
|
+
# Make sure session exist
|
29
|
+
if store_info.blank?
|
30
|
+
return add_rucaptcha_validation_error
|
31
|
+
end
|
32
|
+
|
33
|
+
# Make sure not expire
|
34
|
+
if (Time.now.to_i - store_info[:time]) > RuCaptcha.config.expires_in
|
35
|
+
return add_rucaptcha_validation_error
|
36
|
+
end
|
19
37
|
|
20
|
-
#
|
21
|
-
|
22
|
-
if
|
23
|
-
|
38
|
+
# Make sure parama have captcha
|
39
|
+
captcha = (params[:_rucaptcha] || '').downcase.strip
|
40
|
+
if captcha.blank?
|
41
|
+
return add_rucaptcha_validation_error
|
24
42
|
end
|
25
43
|
|
26
|
-
if
|
27
|
-
|
44
|
+
if captcha != store_info[:code]
|
45
|
+
return add_rucaptcha_validation_error
|
28
46
|
end
|
29
47
|
|
30
|
-
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def add_rucaptcha_validation_error
|
54
|
+
if defined?(resource) && resource && resource.respond_to?(:errors)
|
55
|
+
resource.errors.add(:base, t('rucaptcha.invalid'))
|
56
|
+
end
|
57
|
+
false
|
31
58
|
end
|
32
59
|
end
|
33
60
|
end
|
data/lib/rucaptcha/version.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|