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

Add CAPTCHA to Contact form #881

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"djcelery_email",
"ckeditor",
"drf_yasg",
"captcha",
]

MIDDLEWARE = [
Expand Down
1 change: 1 addition & 0 deletions cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
re_path(r'^swagger(?P<format>\.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')),
]
2 changes: 2 additions & 0 deletions files/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from captcha.fields import CaptchaField
from django import forms

from .methods import get_next_state, is_mediacms_editor
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading