Made the url validator not accept urls from the website

This commit is contained in:
xemeds
2020-07-20 16:53:18 +00:00
parent c1079b6d2b
commit c5f3f5a8c4
5 changed files with 10 additions and 1 deletions
+6
View File
@@ -1,6 +1,7 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, ValidationError
from wtforms.validators import DataRequired, Length
from tiny0.config import WEBSITE_DOMAIN
# Validates a URL
def validate_URL(form, field):
@@ -23,6 +24,11 @@ def validate_URL(form, field):
# Raise a ValidationError
raise ValidationError("Invalid URL")
# If the url contains the websites domain
if WEBSITE_DOMAIN in field.data:
# Raise a ValidationError
raise ValidationError("Invalid URL")
# If the URL does not start with http:// and https://
if not(field.data.startswith("http://")) and not(field.data.startswith("https://")):
# Add https:// to the beginning of the URL