Made the url validator not accept urls from the website
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"WEBSITE_DOMAIN":"127.0.0.1:5000",
|
||||||
"SECRET_KEY": "SECRET_KEY",
|
"SECRET_KEY": "SECRET_KEY",
|
||||||
"SQLALCHEMY_DATABASE_URI": "sqlite:///database.db"
|
"SQLALCHEMY_DATABASE_URI": "sqlite:///database.db"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ with open("tiny0/config.json", "r") as config_file:
|
|||||||
|
|
||||||
config_data = json.load(config_file)
|
config_data = json.load(config_file)
|
||||||
|
|
||||||
|
WEBSITE_DOMAIN = config_data.get("WEBSITE_DOMAIN")
|
||||||
SECRET_KEY = config_data.get("SECRET_KEY")
|
SECRET_KEY = config_data.get("SECRET_KEY")
|
||||||
SQLALCHEMY_DATABASE_URI = config_data.get("SQLALCHEMY_DATABASE_URI")
|
SQLALCHEMY_DATABASE_URI = config_data.get("SQLALCHEMY_DATABASE_URI")
|
||||||
|
|||||||
Binary file not shown.
@@ -1,6 +1,7 @@
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import StringField, SubmitField, ValidationError
|
from wtforms import StringField, SubmitField, ValidationError
|
||||||
from wtforms.validators import DataRequired, Length
|
from wtforms.validators import DataRequired, Length
|
||||||
|
from tiny0.config import WEBSITE_DOMAIN
|
||||||
|
|
||||||
# Validates a URL
|
# Validates a URL
|
||||||
def validate_URL(form, field):
|
def validate_URL(form, field):
|
||||||
@@ -23,6 +24,11 @@ def validate_URL(form, field):
|
|||||||
# Raise a ValidationError
|
# Raise a ValidationError
|
||||||
raise ValidationError("Invalid URL")
|
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 the URL does not start with http:// and https://
|
||||||
if not(field.data.startswith("http://")) and not(field.data.startswith("https://")):
|
if not(field.data.startswith("http://")) and not(field.data.startswith("https://")):
|
||||||
# Add https:// to the beginning of the URL
|
# Add https:// to the beginning of the URL
|
||||||
|
|||||||
+2
-1
@@ -3,6 +3,7 @@ from tiny0 import app, db
|
|||||||
from tiny0.forms import URLForm
|
from tiny0.forms import URLForm
|
||||||
from tiny0.models import URL
|
from tiny0.models import URL
|
||||||
from tiny0.token import gen_valid_token
|
from tiny0.token import gen_valid_token
|
||||||
|
from tiny0.config import WEBSITE_DOMAIN
|
||||||
|
|
||||||
# Index route
|
# Index route
|
||||||
@app.route("/", methods=['GET', 'POST'])
|
@app.route("/", methods=['GET', 'POST'])
|
||||||
@@ -20,7 +21,7 @@ def index():
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Return the url page with the shortened url
|
# Return the url page with the shortened url
|
||||||
return render_template("url.html", url="127.0.0.1:5000/" + token)
|
return render_template("url.html", url=WEBSITE_DOMAIN + "/" + token)
|
||||||
|
|
||||||
# If the form was invalid or not submitted
|
# If the form was invalid or not submitted
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user