diff --git a/tiny0/config.json b/tiny0/config.json index 536a9e4..378eeb7 100644 --- a/tiny0/config.json +++ b/tiny0/config.json @@ -1,4 +1,5 @@ { + "WEBSITE_DOMAIN":"127.0.0.1:5000", "SECRET_KEY": "SECRET_KEY", "SQLALCHEMY_DATABASE_URI": "sqlite:///database.db" } diff --git a/tiny0/config.py b/tiny0/config.py index 3e22084..b5b5047 100644 --- a/tiny0/config.py +++ b/tiny0/config.py @@ -4,5 +4,6 @@ with open("tiny0/config.json", "r") as config_file: config_data = json.load(config_file) + WEBSITE_DOMAIN = config_data.get("WEBSITE_DOMAIN") SECRET_KEY = config_data.get("SECRET_KEY") SQLALCHEMY_DATABASE_URI = config_data.get("SQLALCHEMY_DATABASE_URI") diff --git a/tiny0/database.db b/tiny0/database.db index 5dba130..ef1ce4c 100644 Binary files a/tiny0/database.db and b/tiny0/database.db differ diff --git a/tiny0/forms.py b/tiny0/forms.py index 60ce28f..b3dda3f 100644 --- a/tiny0/forms.py +++ b/tiny0/forms.py @@ -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 diff --git a/tiny0/routes.py b/tiny0/routes.py index 59c802c..3aa8764 100644 --- a/tiny0/routes.py +++ b/tiny0/routes.py @@ -3,6 +3,7 @@ from tiny0 import app, db from tiny0.forms import URLForm from tiny0.models import URL from tiny0.token import gen_valid_token +from tiny0.config import WEBSITE_DOMAIN # Index route @app.route("/", methods=['GET', 'POST']) @@ -20,7 +21,7 @@ def index(): db.session.commit() # 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 else: