[opencms-dev] Friendly Captcha

Jochen Graf j.graf at alkacon.com
Fri Dec 9 13:29:31 CET 2022


Hi,

you can see the integration of an external captcha provider (e.g. 
Friendly Captcha) in the Mercury template.

There are two places in the Java code where the external captcha 
provider widget has to be initialized instead of the standard Mercury 
captcha. The first place is for the case the captcha appears directly 
below the form, the second is for the case the captcha appears on the 
form check page (if activated in the form configuration):

https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.webform/src/alkacon/mercury/webform/fields/CmsCaptchaField.java#L123
https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.webform/src/alkacon/mercury/webform/CmsFormHandler.java#L1498 
(check page)

Initialization in Mercury webform is done by means of a stringtemplate 
attribute called "captchawidget". See the two places in the string 
templates where the captcha widget is used instead of the standard 
Mercury captcha:

https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.webform/resources/system/modules/alkacon.mercury.webform/resources/formtemplates/default.st#L95
https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.webform/resources/system/modules/alkacon.mercury.webform/resources/formtemplates/default.st#L428 
(check page)

The server-side verification of a captcha solution happens here:

https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.webform/src/alkacon/mercury/webform/fields/CmsCaptchaField.java#L222

In order to make the captcha widget and the server-side captcha 
verification of an external provider work, you have to implement an 
interface containing a "getWidgetMarkup" and "verifySolution" method:

https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.template/src/alkacon/mercury/template/captcha/I_CmsCaptchaProvider.java

For FriendlyCaptcha, "getWidgetMarkup" would return a standard 
FriendlyCaptcha HTML markup including a "data-callback" attribute. The 
FriendlyCaptcha callback function would copy the captcha solution into 
the Mercury hidden input field named "captchaphrase": <input 
type="hidden" name="captchaphrase{uuid}" /> which is the one that is 
read and evaluated on the server.

"verifySolution" would simply implement an HTTP client that sends the 
captcha solution read from the hidden input "captchaphrase" to the 
FriendlyCaptcha verification API.

Hope this helps

Jochen


Am 07.12.22 um 13:46 schrieb Schliemann, Kai via opencms-dev:
>
> Hi list,
>
> did any of you already implement the Friendly Captcha solution 
> (https://friendlycaptcha.com) and wants to share the code here?
>
> Or give some hints on how difficult/easy it is to implement the 
> solution with the Alkacon webform modul.
>
> Thanks in advance.
>
> Best regards
>
> Kai
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> https://lists.opencms.org/mailman/listinfo/opencms-dev
>
>
>
-- 
Alkacon Software GmbH & Co. KG  - The OpenCms Experts
http://www.alkacon.com  -http://www.opencms.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opencms.org/pipermail/opencms-dev/attachments/20221209/1ff8e63f/attachment.htm>


More information about the opencms-dev mailing list