hCaptchaUser Guide
hCaptcha 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 hCaptcha responses.
Requires a hCaptcha account to be configured for your domain. See:
Quick Start
Client side code:
using afHcaptcha::CaptchaClient ... siteKey := "..."// siteKey = your unique hCaptcha keyenabled := true// enabled = false to disable hCaptcha during devcaptcha := captchaClient(siteKey, enabled) ... containerId := "divId"// id of where hCaptcha is to be renderedcaptchaId := captcha.render(containerId) ... response := captcha.getResponse(captchaId) 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("captchaInput").setAttr("value", response)
Then when processing form values on the server:
using afIoc::Inject
using afBedSheet::HttpRequest
using afEfanXtra::BeforeRender
using afHcaptcha::CaptchaServer
...
@Inject const HttpRequest httpReq
@Inject const CaptchaServer captcha
@BeforeRender
Void onBeforeRender() {
// inject hCaptcha scripts into the page
captcha.injectJsCaptcha()
}
Void onProcessForm() {
// grab the hCaptcha response from the client form
response := httpReq.body.form["captchaInput"]
// verify it on the hCaptcha server
success := captcha.verifyCaptcha(response, false)
if (success == false)
throw Err("Captcha failed")
}