Google ReCAPTCHAUser Guide
Google ReCAPTCHA is a support library that aids Fantom-Factory Ltd in the development of other libraries, frameworks and applications. Though you are welcome to use it, you may find features are missing and the documentation incomplete.
Overview
Client and Server code to process Google reCAPTCHA responses.
Requires a Google account and reCAPTCHA to be configured on the Admin screen. See:
Quick Start
Client side code:
using afRecaptcha::RecaptchaClient ... siteKey := "..."// siteKey = your unique Google reCAPTCHA keyenabled := true// enabled = false to disable reCAPTCHA during devrecaptcha := RecaptchaClient(siteKey, enabled) ... containerId := "divId"// id of where reCAPTCHA is to be renderedrecaptchaId := recaptcha.render(containerId) ... response := recaptcha.getResponse(recaptchaId) if (response == null) Win.cur.alert("If you're a human, complete the captcha!") else// set a hidden form value to send response to the Serverdoc.elemById("recaptchaInput").setAttr("value", response)
Then when processing form values on the server:
using afIoc::Inject
using afBedSheet::HttpRequest
using afEfanXtra::BeforeRender
using afRecaptcha::RecaptchaServer
...
@Inject const HttpRequest httpReq
@Inject const RecaptchaServer recaptcha
@BeforeRender
Void onBeforeRender() {
// inject Google reCAPTCHA scripts into the page
recaptcha.setupCaptcha()
}
Void onProcessForm() {
// grab the reCAPTCHA response from the form
response := httpReq.body.form["recaptchaInput"]
// verify it with Google
success := recaptcha.verifyCaptcha(response, false)
if (success == false)
throw Err("reCAPTRUE failed")
}