recaptcha_check 0.0.2 → 0.0.4
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 +24 -26
- 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: 7f226b1a1cb1ab493258ed42ef5149b8c1da924923da063b714492fa22011c69
|
4
|
+
data.tar.gz: 164c89ead9687aa401e0d99d3c73695b2e56c09a011b8f9230dc4db0fcdd825c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34c254f8976539ed121404cf7ca20b5975b2e3d156c0099ace84eea53b783a978f4b1db5720080b1a0561f12e55041d47f8d330bf2926057f72e75aa75b674b9
|
7
|
+
data.tar.gz: a65ad6253f046e8d426d04f2506e4f7d15fee402fe6004de65aa772e28146b57c15e5fa9bb6d1b23f2d0ba7c4d85cef4fdbb118c35742c78c8a59fe2034dc28a
|
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_recaptcha
|
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
|
8
|
-
new(response, ip).verify
|
9
|
-
end
|
10
|
-
|
11
|
-
def verify
|
18
|
+
|
19
|
+
def verify_recaptcha
|
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.4
|
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
|