mod_register_web: Switch to the new reCAPTCHA API, including support for "nocaptcha" when users are already signed in to Google.
--- a/mod_register_web/mod_register_web.lua Mon Aug 10 21:13:31 2015 +0200
+++ b/mod_register_web/mod_register_web.lua Wed Mar 04 12:57:24 2015 +0100
@@ -3,6 +3,8 @@
local usermanager = require "core.usermanager";
local http = require "net.http";
local path_sep = package.config:sub(1,1);
+local json = require "util.json".decode;
+local t_concat = table.concat;
module:depends"http";
@@ -47,19 +49,18 @@
}));
end
function verify_captcha(request, form, callback)
- http.request("https://www.google.com/recaptcha/api/verify", {
+ http.request("https://www.google.com/recaptcha/api/siteverify", {
body = http.formencode {
- privatekey = captcha_options.recaptcha_private_key;
+ secret = captcha_options.recaptcha_private_key;
remoteip = request.conn:ip();
- challenge = form.recaptcha_challenge_field;
- response = form.recaptcha_response_field;
+ response = form["g-recaptcha-response"];
};
}, function (verify_result, code)
- local verify_ok, verify_err = verify_result:match("^([^\n]+)\n([^\n]+)");
- if verify_ok == "true" then
+ local result = json(verify_result);
+ if result.success == true then
callback(true);
else
- callback(false, verify_err)
+ callback(false, t_concat(result["error-codes"]));
end
end);
end
--- a/mod_register_web/templates/recaptcha.html Mon Aug 10 21:13:31 2015 +0200
+++ b/mod_register_web/templates/recaptcha.html Wed Mar 04 12:57:24 2015 +0100
@@ -1,11 +1,26 @@
<tr>
<td colspan="2">
- <script src="https://www.google.com/recaptcha/api/challenge?k={recaptcha_public_key}" type="text/javascript"></script>
+ <script src="https://www.google.com/recaptcha/api.js" async defer></script>
+ <div class="g-recaptcha" data-sitekey="{recaptcha_public_key}"></div>
<noscript>
- <iframe frameborder="0" height="300" src="https://www.google.com/recaptcha/api/noscript?k={recaptcha_public_key}{recaptcha_display_error}" width="500"></iframe>
- <br>
- <textarea cols="40" name="recaptcha_challenge_field" rows="3"></textarea>
- <input name="recaptcha_response_field" type="hidden" value="manual_challenge">
+ <div style="width: 302px; height: 352px;">
+ <div style="width: 302px; height: 352px; position: relative;">
+ <div style="width: 302px; height: 352px; position: absolute;">
+ <iframe src="https://www.google.com/recaptcha/api/fallback?k={recaptcha_public_key}"
+ frameborder="0" scrolling="no"
+ style="width: 302px; height:352px; border-style: none;">
+ </iframe>
+ </div>
+ <div style="width: 250px; height: 80px; position: absolute; border-style: none;
+ bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;">
+ <textarea id="g-recaptcha-response" name="g-recaptcha-response"
+ class="g-recaptcha-response"
+ style="width: 250px; height: 80px; border: 1px solid #c1c1c1;
+ margin: 0px; padding: 0px; resize: none;" value="">
+ </textarea>
+ </div>
+ </div>
+ </div>
</noscript>
</td>
</tr>