Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you add hcaptcha to the registration form? #10

Open
mauritsvanrees opened this issue Jan 20, 2023 · 1 comment
Open

How do you add hcaptcha to the registration form? #10

mauritsvanrees opened this issue Jan 20, 2023 · 1 comment

Comments

@mauritsvanrees
Copy link
Sponsor Member

I am trying this in Plone 5.2, Python 3.8.
The readme says you can add this in an XML model:

<field name="captcha" type="plone.formwidget.hcaptcha.HCaptchaWidget">
  <title>Solve Captcha</title>
  <description></description>
</field>

I think this needs to be HCaptchaField instead of a widget.

When I add this to userschema.xml in a GS profile and import it, I get a warning and the field is ignored:

INFO    [plone.app.users.browser.schemaeditor:78][waitress-0] Unsupported field: captcha (CaptchaField)

Looking further, I add a patch to add captcha to two lists in plone.app.users:

full_field = "plone.formwidget.hcaptcha.HCaptchaField"
if full_field not in schemaeditor.ALLOWED_FIELDS:
    schemaeditor.ALLOWED_FIELDS.append(full_field)
field_class = "HCaptchaField"
if field_class not in schemaeditor.field_type_mapping:
    schemaeditor.field_type_mapping[field_class] = "string"
logger.info("Added hcaptcha to allowed fields and mapping in plone.app.users")

With this I no longer get the warning about an unsupported field. But importing fails, because plone.supermodel does not support it:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 376, in publish_module
  Module ZPublisher.WSGIPublisher, line 271, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module Products.GenericSetup.tool, line 577, in manage_importSelectedSteps
  Module Products.GenericSetup.tool, line 375, in runImportStepFromProfile
  Module Products.GenericSetup.tool, line 1323, in _doRunImportStep
   - __traceback_info__: usersschema
  Module plone.app.users.setuphandlers, line 21, in import_schema
  Module plone.app.users.browser.schemaeditor, line 136, in applySchema
  Module plone.app.users.browser.schemaeditor, line 178, in get_ttw_edited_schema
  Module plone.app.users.browser.schemaeditor, line 275, in load_ttw_schema
  Module plone.supermodel, line 37, in loadString
  Module plone.supermodel.parser, line 78, in parse
plone.supermodel.parser.SupermodelParseError: Field type plone.formwidget.hcaptcha.HCaptchaField specified for field captcha is not supported
  File "<unknown>", line 79
  File "/Users/maurits/shared-eggs/cp38/plone.supermodel-1.6.5-py3.8.egg/plone/supermodel/parser.py", line 72, in parse
    return _parse(source, policy)
  File "/Users/maurits/shared-eggs/cp38/plone.supermodel-1.6.5-py3.8.egg/plone/supermodel/parser.py", line 161, in _parse
    readField(
  File "/Users/maurits/shared-eggs/cp38/plone.supermodel-1.6.5-py3.8.egg/plone/supermodel/parser.py", line 121, in readField
    raise ValueError(

The zcml of plone.formwidget.hcaptcha does get loaded, and it has some code for supermodel.

In the TTW schema editor (the member-fields view) no options for adding a captcha are visible either. I suppose this is also due to some missing supermodel/schemaeditor integration.

Does anyone know what is missing? Maybe someone has a patch lying around already?

@fredvd
Copy link
Sponsor Member

fredvd commented Jan 20, 2023

The hacaptcha code is 1:1 taken from the recaptcha addon And then adapted. So any issues here will also be valid for plone.formwidget.recaptcha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants