bootleg anti-spam measure

master
vilmibm 2019-12-16 22:22:01 +00:00
parent 2385446e74
commit 77d728a153
1 changed files with 6 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import re
from django.shortcuts import redirect
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
@ -5,6 +7,8 @@ from django.views.generic.edit import FormView
from .forms import GuestbookForm
from .models import GuestbookMessage
SUSPICIOUS_RE = re.compile(r'https?://')
class GuestbookView(FormView):
form_class = GuestbookForm
@ -17,5 +21,7 @@ class GuestbookView(FormView):
def form_valid(self, form):
del form.cleaned_data['captcha']
if SUSPICIOUS_RE.search(form.cleaned_data['msg']) != None:
return redirect('guestbook:guestbook')
t = GuestbookMessage.objects.create(**form.cleaned_data)
return redirect('guestbook:guestbook')