failing the captcha no longer returns a 500
This commit is contained in:
parent
8631a0259e
commit
3eb3dfca48
|
@ -1,3 +1,4 @@
|
|||
from re import Pattern
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as txt
|
||||
|
@ -11,5 +12,5 @@ class SignbookForm(forms.Form):
|
|||
|
||||
def validate_capcha(self):
|
||||
if self.cleaned_data["capcha"].lower() != "i love me":
|
||||
raise ValidationError(txt('Invalid captcha'))
|
||||
raise ValidationError(txt('Invalid captcha'), code="invalid")
|
||||
return self
|
|
@ -1,3 +1,4 @@
|
|||
from django.forms import ValidationError
|
||||
from django.http import HttpResponseNotFound, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
import os, random
|
||||
|
@ -47,46 +48,59 @@ def signbook(request):
|
|||
signer_list = Booksigner.objects.all()
|
||||
if request.method == 'POST':
|
||||
form = SignbookForm(request.POST)
|
||||
if form.is_valid() and form.validate_capcha():
|
||||
newsigner = {}
|
||||
newsigner["name"] = form.cleaned_data['name']
|
||||
newsigner["website"] = form.cleaned_data['website']
|
||||
newsigner["email"] = form.cleaned_data['email']
|
||||
newsigner["comment"] = form.cleaned_data['comment']
|
||||
host = request.META["SERVER_NAME"]
|
||||
print(host)
|
||||
match host:
|
||||
case "localhost":
|
||||
newsigner["hosting"] = "Local"
|
||||
case r".*\.fai.st":
|
||||
newsigner["hosting"] = "fai"
|
||||
case _:
|
||||
newsigner["hosting"] = "???"
|
||||
try:
|
||||
if form.is_valid() and form.validate_capcha():
|
||||
newsigner = {}
|
||||
newsigner["name"] = form.cleaned_data['name']
|
||||
newsigner["website"] = form.cleaned_data['website']
|
||||
newsigner["email"] = form.cleaned_data['email']
|
||||
newsigner["comment"] = form.cleaned_data['comment']
|
||||
host = request.META["SERVER_NAME"]
|
||||
print(host)
|
||||
match host:
|
||||
case "localhost":
|
||||
newsigner["hosting"] = "Local"
|
||||
case r".*\.fai.st":
|
||||
newsigner["hosting"] = "fai"
|
||||
case _:
|
||||
newsigner["hosting"] = "???"
|
||||
|
||||
signer_list = Booksigner.objects.all()
|
||||
if newsigner:
|
||||
Booksigner.objects.create(
|
||||
name=newsigner["name"],
|
||||
email=newsigner["email"],
|
||||
website=newsigner["website"],
|
||||
comment=newsigner["comment"],
|
||||
hosting=newsigner["hosting"],
|
||||
)
|
||||
signer_list = Booksigner.objects.all()
|
||||
if newsigner:
|
||||
Booksigner.objects.create(
|
||||
name=newsigner["name"],
|
||||
email=newsigner["email"],
|
||||
website=newsigner["website"],
|
||||
comment=newsigner["comment"],
|
||||
hosting=newsigner["hosting"],
|
||||
)
|
||||
context = {
|
||||
"title": "THE GUESTBOOK",
|
||||
"signer_list": signer_list
|
||||
}
|
||||
return render(request, "signbook.html", context)
|
||||
context = {
|
||||
"title": "THE GUESTBOOK",
|
||||
"signer_list": signer_list
|
||||
"signer_list": signer_list,
|
||||
"error_message": "You didn't input a required input.",
|
||||
}
|
||||
return render(request, "signbook.html", context)
|
||||
context = {
|
||||
"title": "THE GUESTBOOK",
|
||||
"signer_list": signer_list,
|
||||
"error_message": "You didn't input a required input.",
|
||||
}
|
||||
return render(
|
||||
request,
|
||||
"signbook.html",
|
||||
context
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
"signbook.html",
|
||||
context
|
||||
)
|
||||
except ValidationError as e:
|
||||
print("Error: ", e)
|
||||
context = {
|
||||
"title": "THE GUESTBOOK",
|
||||
"signer_list": signer_list,
|
||||
"error_message": "Invalid captcha.",
|
||||
}
|
||||
return render(
|
||||
request,
|
||||
"signbook.html",
|
||||
context
|
||||
)
|
||||
else:
|
||||
context = {
|
||||
"title": "THE GUESTBOOK",
|
||||
|
|
Loading…
Reference in New Issue