fix errors when empty optinal values

This commit is contained in:
fram3d 2024-01-18 23:34:01 +01:00
parent 673c04af19
commit 44b7228982
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
3 changed files with 30 additions and 18 deletions

View File

@ -8,4 +8,4 @@ Depends: gunicorn, python3-flask-sqlalchemy
Homepage: https://gitea.dmz.rs/Decentrala/taskmanager Homepage: https://gitea.dmz.rs/Decentrala/taskmanager
Maintainer: Decentrala <dmz@dmz.rs> Maintainer: Decentrala <dmz@dmz.rs>
Description: Interactive TODO list Web app Description: Interactive TODO list Web app
Version: 1.0.7 Version: 1.0.9

View File

@ -25,16 +25,13 @@ def addtask():
taskdesc = request.form['taskdesc'] taskdesc = request.form['taskdesc']
username = request.form['username'] username = request.form['username']
# Input sanitation # Input sanitation
# Task name
if not taskname.isalnum(): if not taskname.isalnum():
return render_template('response.html', response = "Task name has to be made only of letters or numbers.") 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: if len(taskname) < 1 or len(taskname) > 40:
return render_template('response.html', response = "Task name lenght invalid, only smaller then 40 charachters allowed") 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 == "": if username == "":
creatorid = None creatorid = None
else: else:
@ -44,6 +41,13 @@ def addtask():
return render_template('response.html', response = 'No user with this username. Please <a href="/register">register</a>.') return render_template('response.html', response = 'No user with this username. Please <a href="/register">register</a>.')
if creatorid is None: if creatorid is None:
return render_template('response.html', response = 'No user with this username. Please <a href="/register">register</a>.') return render_template('response.html', response = 'No user with this username. Please <a href="/register">register</a>.')
# 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) sqladdtask = Task(name = taskname, desc = taskdesc, creatorid = creatorid)
try: try:
db.session.add(sqladdtask) db.session.add(sqladdtask)
@ -60,18 +64,27 @@ def register():
username = request.form['username'] username = request.form['username']
contact = request.form['contact'] contact = request.form['contact']
password = request.form['password'] password = request.form['password']
# Username
if not username.isalnum(): if not username.isalnum():
return render_template('response.html', response = "Username has to be made only of letters or numbers.") 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: if len(username) < 1 or len(username) > 40:
return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed") return render_template('response.html', response = "Username lenght invalid, only smaller then 40 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: if len(contact) > 100:
return render_template('response.html', response = "Contact lenght invalid, only smaller then 100 charachters allowed") 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: if len(password) > 500:
return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed") return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed")
sqladduser = User(username = username, contact = contact, password = password) sqladduser = User(username = username, contact = contact, password = password)
try: try:
db.session.add(sqladduser) db.session.add(sqladduser)
@ -96,9 +109,8 @@ def project(task_id:int):
if request.method == 'GET': if request.method == 'GET':
return render_template("project.html", task = task, users = users) return render_template("project.html", task = task, users = users)
elif request.method == 'POST': elif request.method == 'POST':
# Assigning user to task
username = request.form['username'] 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: for user in users:
if username == user.username: if username == user.username:
return render_template('response.html', response = 'User already added to task') return render_template('response.html', response = 'User already added to task')

View File

@ -4,7 +4,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/static/style.css" /> <link rel="stylesheet" href="/static/style.css" />
<title>{{task.name}}</title> <title>{{response}}</title>
</head> </head>
<body> <body>
<header> <header>