From 44b7228982b40306fee1f8ab754037a9dd21fcdc Mon Sep 17 00:00:00 2001 From: fram3d Date: Thu, 18 Jan 2024 23:34:01 +0100 Subject: [PATCH] fix errors when empty optinal values --- build-deb/taskmanager/DEBIAN/control | 2 +- taskmanager/routes.py | 44 ++++++++++++++++++---------- taskmanager/templates/response.html | 2 +- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/build-deb/taskmanager/DEBIAN/control b/build-deb/taskmanager/DEBIAN/control index ccc0b6c..9d18c79 100644 --- a/build-deb/taskmanager/DEBIAN/control +++ b/build-deb/taskmanager/DEBIAN/control @@ -8,4 +8,4 @@ Depends: gunicorn, python3-flask-sqlalchemy Homepage: https://gitea.dmz.rs/Decentrala/taskmanager Maintainer: Decentrala Description: Interactive TODO list Web app -Version: 1.0.7 +Version: 1.0.9 diff --git a/taskmanager/routes.py b/taskmanager/routes.py index 252e07c..9cd227a 100644 --- a/taskmanager/routes.py +++ b/taskmanager/routes.py @@ -25,16 +25,13 @@ def addtask(): taskdesc = request.form['taskdesc'] username = request.form['username'] # Input sanitation + # Task name if not taskname.isalnum(): return render_template('response.html', response = "Task name has to be made only of letters or numbers.") - if not username.isalnum(): - return render_template('response.html', response = "Username has to be made only of letters or numbers.") - if not taskdesc.isprintable(): - return render_template('response.html', response = "Task description has to be made of printable characters.") if len(taskname) < 1 or len(taskname) > 40: return render_template('response.html', response = "Task name lenght invalid, only smaller then 40 charachters allowed") - if len(taskdesc) > 2000: - return render_template('response.html', response = "Task description lenght invalid, only smaller then 2000 charachters allowed") + + # Username if username == "": creatorid = None else: @@ -44,6 +41,13 @@ def addtask(): return render_template('response.html', response = 'No user with this username. Please register.') if creatorid is None: return render_template('response.html', response = 'No user with this username. Please register.') + + # Task descripton + if taskdesc != '': + if not taskdesc.isprintable(): + return render_template('response.html', response = "Task description has to be made of printable characters.") + if len(taskdesc) > 2000: + return render_template('response.html', response = "Task description lenght invalid, only smaller then 2000 charachters allowed") sqladdtask = Task(name = taskname, desc = taskdesc, creatorid = creatorid) try: db.session.add(sqladdtask) @@ -60,18 +64,27 @@ def register(): username = request.form['username'] contact = request.form['contact'] password = request.form['password'] + + # Username if not username.isalnum(): return render_template('response.html', response = "Username has to be made only of letters or numbers.") - if not contact.isprintable(): - return render_template('response.html', response = "Contact information has to be made of printable characters.") - if not password.isprintable(): - return render_template('response.html', response = "Password has to be made of printable characters.") if len(username) < 1 or len(username) > 40: return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed") - if len(contact) > 100: - return render_template('response.html', response = "Contact lenght invalid, only smaller then 100 charachters allowed") - if len(password) > 500: - return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed") + + # Contact + if contact != '': + if not contact.isprintable(): + return render_template('response.html', response = "Contact information has to be made of printable characters.") + if len(contact) > 100: + return render_template('response.html', response = "Contact lenght invalid, only smaller then 100 charachters allowed") + + # Password + if password != '': + if not password.isprintable(): + return render_template('response.html', response = "Password has to be made of printable characters.") + if len(password) > 500: + return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed") + sqladduser = User(username = username, contact = contact, password = password) try: db.session.add(sqladduser) @@ -96,9 +109,8 @@ def project(task_id:int): if request.method == 'GET': return render_template("project.html", task = task, users = users) elif request.method == 'POST': + # Assigning user to task username = request.form['username'] - if len(username) < 1 or len(username) > 40: - return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed") for user in users: if username == user.username: return render_template('response.html', response = 'User already added to task') diff --git a/taskmanager/templates/response.html b/taskmanager/templates/response.html index e62e36a..4dd8229 100644 --- a/taskmanager/templates/response.html +++ b/taskmanager/templates/response.html @@ -4,7 +4,7 @@ - {{task.name}} + {{response}}