mirror of
https://codeberg.org/angestoepselt/homepage.git
synced 2025-05-24 14:46:16 +00:00
Validate Email regex before submitting forms
This commit is contained in:
parent
f36e4d1548
commit
717acb8efe
1 changed files with 7 additions and 0 deletions
|
|
@ -34,6 +34,9 @@ except IOError:
|
||||||
|
|
||||||
|
|
||||||
HONEYPOT_FIELD_NAME = "addressline1"
|
HONEYPOT_FIELD_NAME = "addressline1"
|
||||||
|
# This regex merely validates what the in-browser form validation already checks and
|
||||||
|
# isn't all too strict.
|
||||||
|
EMAIL_REGEX = re.compile(r"^[^ ]+@[^ ]+\.[^ ]+$")
|
||||||
|
|
||||||
SITE_DIRECTORY = os.environ.get("SITE_DIRECTORY", "")
|
SITE_DIRECTORY = os.environ.get("SITE_DIRECTORY", "")
|
||||||
request_uri = os.environ.get("REQUEST_URI", "").lower().rstrip("/")
|
request_uri = os.environ.get("REQUEST_URI", "").lower().rstrip("/")
|
||||||
|
|
@ -183,7 +186,11 @@ if not isinstance(hcaptcha_data, Mapping) or not hcaptcha_data.get("success", Fa
|
||||||
# Extract all the actually provided form data. This is different from form to
|
# Extract all the actually provided form data. This is different from form to
|
||||||
# form (see the match block below).
|
# form (see the match block below).
|
||||||
contact_name = get_form_value("contactname")
|
contact_name = get_form_value("contactname")
|
||||||
|
|
||||||
contact_email = get_form_value("contactemail")
|
contact_email = get_form_value("contactemail")
|
||||||
|
if not EMAIL_REGEX.fullmatch(contact_email):
|
||||||
|
fail("400 Bad Request", "Invalid Email address")
|
||||||
|
|
||||||
message = get_form_value("message", "[Keine Nachricht hinterlassen]")
|
message = get_form_value("message", "[Keine Nachricht hinterlassen]")
|
||||||
attachment: Optional[tuple[str, bytes]] = None
|
attachment: Optional[tuple[str, bytes]] = None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue