Module: NewGoogleRecaptcha
- Defined in:
- lib/new_google_recaptcha.rb,
lib/new_google_recaptcha/railtie.rb,
lib/new_google_recaptcha/version.rb,
lib/new_google_recaptcha/view_ext.rb,
lib/new_google_recaptcha/validator.rb
Defined Under Namespace
Modules: ViewExt
Classes: Railtie, Validator
Constant Summary
collapse
- VERSION =
'1.1.0'
Class Method Summary
collapse
Class Method Details
.compose_uri(token) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/new_google_recaptcha.rb', line 52
def self.compose_uri(token)
URI(
"https://www.google.com/recaptcha/api/siteverify?"\
"secret=#{self.secret_key}&response=#{token}"
)
end
|
.get_humanity_detailed(token, action, minimum_score = self.minimum_score, model = nil) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/new_google_recaptcha.rb', line 27
def self.get_humanity_detailed(token, action, minimum_score = self.minimum_score, model = nil)
validator =
NewGoogleRecaptcha::Validator.new(
token: token,
action: action,
minimum_score: minimum_score
)
is_valid = validator.call
if model && !is_valid
model.errors.add(:base, self.i18n("new_google_recaptcha.errors.verification_human", "Looks like you are not a human"))
end
{ is_human: is_valid, score: validator.score, model: model }
end
|
.human?(token, action, minimum_score = self.minimum_score, model = nil) ⇒ Boolean
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/new_google_recaptcha.rb', line 12
def self.human?(token, action, minimum_score = self.minimum_score, model = nil)
is_valid =
NewGoogleRecaptcha::Validator.new(
token: token,
action: action,
minimum_score: minimum_score
).call
if model && !is_valid
model.errors.add(:base, self.i18n("new_google_recaptcha.errors.verification_human", "Looks like you are not a human"))
end
is_valid
end
|
.i18n(key, default) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/new_google_recaptcha.rb', line 44
def self.i18n(key, default)
if defined?(I18n)
I18n.translate(key, default: default)
else
default
end
end
|
.setup {|_self| ... } ⇒ Object
8
9
10
|
# File 'lib/new_google_recaptcha.rb', line 8
def self.setup
yield(self)
end
|