7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/recaptcha/verify.rb', line 7
def verify_recaptcha(options = {})
options = { :model => options } unless options.is_a? Hash
return true if Recaptcha::Verify.skip?(options[:env])
model = options[:model]
attribute = options[:attribute] || :base
recaptcha_response = options[:response] || params['g-recaptcha-response'].to_s
begin
verified = if recaptcha_response.empty?
false
else
recaptcha_verify_via_api_call(request, recaptcha_response, options)
end
if verified
flash.delete(:recaptcha_error) if recaptcha_flash_supported? && !model
true
else
recaptcha_error(
model,
attribute,
options[:message],
"recaptcha.errors.verification_failed",
"reCAPTCHA verification failed, please try again."
)
false
end
rescue Timeout::Error
if Recaptcha.configuration.handle_timeouts_gracefully
recaptcha_error(
model,
attribute,
options[:message],
"recaptcha.errors.recaptcha_unreachable",
"Oops, we failed to validate your reCAPTCHA response. Please try again."
)
false
else
raise RecaptchaError, "Recaptcha unreachable."
end
rescue StandardError => e
raise RecaptchaError, e.message, e.backtrace
end
end
|