ReCAPTCHA for Bones
Protects forms with a reCAPTCHA to prevent machines pretending to be humans from abusing a service.
-
Add your API keys to your configuration JSON file:
{ "recaptchaPrivateKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "recaptchaPublicKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }
-
To add a captcha to a form, add
<%= this.ReCaptcha() %>
to your form template code. -
Protect your form/model submission endpoint with
this.post('/endpoint-url', servers.ReCaptcha.verifyReCaptcha); this.put('/endpoint-url', servers.ReCaptcha.verifyReCaptcha); this.del('/endpoint-url', servers.ReCaptcha.verifyReCaptcha);
-
When submitting the form via AJAX, make sure you include these fields:
var data = { recaptcha_challenge_field: Recaptcha.get_challenge(), recaptcha_response_field: Recaptcha.get_response() };
-
In the error handler, call
Recaptcha.reload();
to display a new captcha.