diff --git a/cms/settings.py b/cms/settings.py index 79452156d..3847aeb67 100644 --- a/cms/settings.py +++ b/cms/settings.py @@ -299,6 +299,7 @@ "djcelery_email", "ckeditor", "drf_yasg", + "captcha", ] MIDDLEWARE = [ diff --git a/cms/urls.py b/cms/urls.py index bdf038b32..7de26d717 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -28,4 +28,5 @@ re_path(r'^swagger(?P\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), path('docs/api/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), + path('captcha/', include('captcha.urls')), ] diff --git a/files/forms.py b/files/forms.py index a36c0ca61..2aa4446e8 100644 --- a/files/forms.py +++ b/files/forms.py @@ -1,3 +1,4 @@ +from captcha.fields import CaptchaField from django import forms from .methods import get_next_state, is_mediacms_editor @@ -79,6 +80,7 @@ class ContactForm(forms.Form): from_email = forms.EmailField(required=True) name = forms.CharField(required=False) message = forms.CharField(widget=forms.Textarea, required=True) + captcha = CaptchaField() def __init__(self, user, *args, **kwargs): super(ContactForm, self).__init__(*args, **kwargs) diff --git a/files/views.py b/files/views.py index ce90196d0..b401feff7 100644 --- a/files/views.py +++ b/files/views.py @@ -147,6 +147,8 @@ def contact(request): email.send(fail_silently=True) success_msg = "Message was sent! Thanks for contacting" context["success_msg"] = success_msg + else: + context["success_msg"] = "The information you entered was invalid. Please click Back and try again." return render(request, "cms/contact.html", context) diff --git a/requirements.txt b/requirements.txt index acbb677a8..563dc3186 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ m3u8==3.5.0 django-ckeditor==6.6.1 django-debug-toolbar==4.1.0 django-login-required-middleware==0.9.0 +django-simple-captcha==0.5.18