diff --git a/src/agenda_culturel/settings/base.py b/src/agenda_culturel/settings/base.py index 9df688b..646507b 100644 --- a/src/agenda_culturel/settings/base.py +++ b/src/agenda_culturel/settings/base.py @@ -56,8 +56,11 @@ INSTALLED_APPS = [ "robots", "debug_toolbar", "cache_cleaner", + "honeypot", ] +HONEYPOT_FIELD_NAME = "alias_name" + SITE_ID = 1 MIDDLEWARE = [ diff --git a/src/agenda_culturel/templates/agenda_culturel/contactmessage_create_form.html b/src/agenda_culturel/templates/agenda_culturel/contactmessage_create_form.html index a8ab063..d3acd2b 100644 --- a/src/agenda_culturel/templates/agenda_culturel/contactmessage_create_form.html +++ b/src/agenda_culturel/templates/agenda_culturel/contactmessage_create_form.html @@ -1,5 +1,6 @@ {% extends "agenda_culturel/page-admin.html" %} {% load static %} +{% load honeypot %} {% block title %}{% block og_title %}{% if form.event %}Contact au sujet de l'événement {{ form.event.title }}{% else %} Contact{% endif %}{% endblock %}{% endblock %} @@ -40,6 +41,7 @@ Contact{% endif %}{% endblock %}{% endblock %} {% endif %}
{% csrf_token %} + {% render_honeypot_field "alias_name" %} {{ form.media }} {{ form.as_p }} diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 46d417b..a888639 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -10,6 +10,9 @@ from django import forms from django.http import Http404 from django.contrib.postgres.search import SearchQuery, SearchHeadline from django.utils.safestring import mark_safe +from django.utils.decorators import method_decorator +from honeypot.decorators import check_honeypot + from django.contrib.gis.geos import Point from django.contrib.gis.measure import D @@ -723,7 +726,7 @@ def export_ical(request): return response - +@method_decorator(check_honeypot, name='post') class ContactMessageCreateView(SuccessMessageMixin, CreateView): model = ContactMessage template_name = "agenda_culturel/contactmessage_create_form.html" diff --git a/src/requirements.txt b/src/requirements.txt index 4f71636..a0989ee 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -42,4 +42,5 @@ django-location-field==2.7.3 django-robots==6.1 django-debug-toolbar==4.4.6 django-cache-cleaner==0.1.0 -emoji==2.14.0 \ No newline at end of file +emoji==2.14.0 +django-honeypot==1.2.1 \ No newline at end of file