recaptcha_plugin.rb
1.27 KB
1
2
3
4
5
6
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
class RecaptchaPlugin < Noosfero::Plugin
def self.plugin_name
_('Google reCAPTCHA plugin')
end
def self.plugin_description
_("Provides a plugin to Google reCAPTCHA.")
end
def self.api_mount_points
[RecaptchaPlugin::API ]
end
def test_captcha(*args)
remote_ip = args[0]
params = args[1]
environment = args[2]
private_key = environment.recaptcha_private_key
version = environment.recaptcha_version
msg_icve = _('Internal captcha validation error')
msg_esca = 'Environment recaptcha_plugin_attributes'
return RecaptchaVerification.hash_error(msg_icve, s, nil, "#{msg_eacs} private_key not defined") if private_key.nil?
return RecaptchaVerification.hash_error(msg_icve, s, nil, "#{msg_eacs} version not defined") unless version == 1 || version == 2
rv = RecaptchaVerification.new
if version == 1
verify_uri = 'https://www.google.com/recaptcha/api/verify'
return rv.verify_recaptcha_v1(remote_ip, private_key, verify_uri, params[:recaptcha_challenge_field], params[:recaptcha_response_field])
end
if version == 2
verify_uri = 'https://www.google.com/recaptcha/api/siteverify'
return rv.verify_recaptcha_v2(remote_ip, private_key, verify_uri, params[:g_recaptcha_response])
end
end
end