diff --git a/README.md b/README.md index c504efe..b938f48 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,12 @@ These are the options that can be specified in your .ini config file. | `ckanext.contact.recaptcha_v3_secret` | API secret for the reCAPTCHA service. | False (i.e. disabled) | | `ckanext.contact.recaptcha_v3_action` | `data-module-action` for the form/button | | +## Other + +| Name | Description | Default | +|-------------------------------|------------------------------------------------------------------------------------------------------|---------------------| +| `ckanext.contact.check_email` | Set to False to disable checking email addresses via [pyIsEmail](https://pypi.org/project/pyIsEmail) | True (i.e. enabled) | + # Usage @@ -107,7 +113,7 @@ Add the following HTML where you want the contact button to appear: {{ link_text if link_text else _('CONTACT BUTTON TEXT') }} -{% resource 'ckanext-contact/main' %} +{% asset 'ckanext-contact/main' %} ``` Where `params` is a dict with three entries: package_id, resource_id, record_id (all of which are optional). diff --git a/ckanext/contact/routes/_helpers.py b/ckanext/contact/routes/_helpers.py index a61c29d..52715ea 100644 --- a/ckanext/contact/routes/_helpers.py +++ b/ckanext/contact/routes/_helpers.py @@ -13,6 +13,7 @@ from ckanext.contact import recaptcha from ckanext.contact.interfaces import IContact from datetime import datetime, timezone +from pyisemail import is_email log = logging.getLogger(__name__) @@ -42,6 +43,15 @@ def validate(data_dict): errors[field] = ['Missing Value'] error_summary[field] = 'Missing value' + # check the email address, if there is one and the config option isn't off + if ( + toolkit.asbool(toolkit.config.get('ckanext.contact.check_email', True)) + and data_dict['email'] + ): + if not is_email(data_dict['email'], check_dns=True): + errors['email'] = ['Email address appears to be invalid'] + error_summary['email'] = 'Email address appears to be invalid' + # only check the recaptcha if there are no errors if not errors: try: diff --git a/ckanext/contact/theme/templates/contact/snippets/form.html b/ckanext/contact/theme/templates/contact/snippets/form.html index ec3c031..b9a39cd 100644 --- a/ckanext/contact/theme/templates/contact/snippets/form.html +++ b/ckanext/contact/theme/templates/contact/snippets/form.html @@ -30,7 +30,7 @@ value=data.subject, error=errors.subject, classes=['control-medium'], is_required=false, placeholder=_('Optional subject')) }} - {{ form.markdown('content', label=_('Your Request'), id='field-content', + {{ form.textarea('content', label=_('Your Request'), id='field-content', value=data.content, error=errors.content, placeholder=_('What do you have to tell us?'), is_required=true) }} {% endblock %} diff --git a/ckanext/contact/theme/templates/contact/success.html b/ckanext/contact/theme/templates/contact/success.html index fc0534f..389df41 100644 --- a/ckanext/contact/theme/templates/contact/success.html +++ b/ckanext/contact/theme/templates/contact/success.html @@ -5,7 +5,7 @@

Thank you!

-

Your comment has been sent, we will answer you as soon as possible.

+

Your comment has been sent and we will answer you as soon as possible.

diff --git a/pyproject.toml b/pyproject.toml index 7b11181..433af3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,8 @@ classifiers = [ "Programming Language :: Python :: 3.8" ] dependencies = [ - "ckantools>=0.3.0" + "ckantools>=0.3.0", + "pyisemail==2.0.1" ] [project.optional-dependencies]