recaptcha_check 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/recaptcha_check.rb +23 -25
- metadata +1 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5aa064a9eac3bab96394c495866efae18a3d4f208ec6ea7d1348f169ad77dfa
|
4
|
+
data.tar.gz: cc5df9e982a043753e04caf2c5948f9a89498c2c578565bdd7fe7600b734a975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4beecbb25ddaa0116e7abd209789a1288f6f2b303ba2b8544340ad606355f8aa8b976fbadcdef1edf8c3d0de9caa93613bed261730cc8ffb1c7094f86d17322d
|
7
|
+
data.tar.gz: 301c5d4f178c9488b0e89d3e262fd66c015bfa5ab15878853562fd4dc4a46150928e7696ce6f3b2ab326b70594a6576dff55b29ed497c1bcf5935af2dc1ee8e4
|
data/lib/recaptcha_check.rb
CHANGED
@@ -1,43 +1,41 @@
|
|
1
|
-
class RecaptchaCheck
|
1
|
+
class RecaptchaCheck
|
2
|
+
def self.verify(params, ip = nil)
|
3
|
+
new(params['g-recaptcha-response'], ip).verify
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.register(recaptcha_secret_key)
|
7
|
+
ENV[RECAPTCHACHECK_SECRET_KEY] = recaptcha_secret_key
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
RECAPTCHACHECK_SECRET_KEY = 'RECAPTCHACHECK_SECRET_KEY'.freeze
|
13
|
+
|
2
14
|
def initialize(response, ip)
|
3
15
|
@response = response
|
4
16
|
@ip = ip
|
5
17
|
end
|
6
|
-
|
7
|
-
def self.verify(response, ip = nil)
|
8
|
-
new(response, ip).verify
|
9
|
-
end
|
10
|
-
|
18
|
+
|
11
19
|
def verify
|
12
20
|
require 'httparty'
|
13
|
-
recaptcha_response = HTTParty.get(recaptcha_url(@response, secret, @ip))
|
14
|
-
response_success?(recaptcha_response)
|
21
|
+
recaptcha_response = HTTParty.get(recaptcha_url(@response, self.secret, @ip))
|
22
|
+
self.response_success?(recaptcha_response)
|
15
23
|
end
|
16
|
-
|
17
|
-
private
|
18
24
|
|
19
|
-
RECAPTCHA_PRIVATE_KEY = 'RECAPTCHA_PRIVATE_KEY'.freeze
|
20
|
-
|
21
25
|
def recaptcha_url(response, secret, ip)
|
22
26
|
"https://www.google.com/recaptcha/api/siteverify?secret=#{secret}&response=#{response}&remoteip=#{ip}"
|
23
27
|
end
|
24
28
|
|
29
|
+
def response_success?(response)
|
30
|
+
response.fetch('success')
|
31
|
+
end
|
32
|
+
|
25
33
|
def secret
|
26
|
-
if not self.secret_defined?
|
27
|
-
|
28
|
-
Envl.auto_load
|
29
|
-
|
30
|
-
puts "#{RECAPTCHA_PRIVATE_KEY} is not defined in ENV." if not self.secret_defined?
|
31
|
-
end
|
32
|
-
|
33
|
-
ENV[RECAPTCHA_PRIVATE_KEY]
|
34
|
+
raise "Use RecaptchaCheck#register to set the reCAPTCHA secret key." if not self.secret_defined?
|
35
|
+
ENV[RECAPTCHACHECK_SECRET_KEY]
|
34
36
|
end
|
35
37
|
|
36
38
|
def secret_defined?
|
37
|
-
not ENV[
|
38
|
-
end
|
39
|
-
|
40
|
-
def response_success?(response)
|
41
|
-
response.fetch('success')
|
39
|
+
not ENV[RECAPTCHACHECK_SECRET_KEY].nil?
|
42
40
|
end
|
43
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recaptcha_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Stauffer
|
@@ -10,26 +10,6 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: envl
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.0'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.0.8
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.0'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.0.8
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: httparty
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|