Skip to content

Commit

Permalink
merge: PR #50 from dev
Browse files Browse the repository at this point in the history
Weekly release 2024-01-15
  • Loading branch information
alycejenni authored Jan 15, 2024
2 parents f346c1b + 060c3a7 commit 61c277b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

<!--configuration-end-->

# Usage
Expand All @@ -107,7 +113,7 @@ Add the following HTML where you want the contact button to appear:
<i class="fas fa-envelope"></i>{{ link_text if link_text else _('CONTACT BUTTON TEXT') }}
</a>
{% 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).
Expand Down
10 changes: 10 additions & 0 deletions ckanext/contact/routes/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ckanext/contact/theme/templates/contact/snippets/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/contact/theme/templates/contact/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<article class="module">
<div class="module-content">
<h1 class="page-heading">Thank you!</h1>
<p>Your comment has been sent, we will answer you as soon as possible.</p>
<p>Your comment has been sent and we will answer you as soon as possible.</p>

</div>
</article>
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 61c277b

Please sign in to comment.