diff --git a/build-deb/taskmanager/DEBIAN/control b/build-deb/taskmanager/DEBIAN/control index 12588d2..ccc0b6c 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.6 +Version: 1.0.7 diff --git a/taskmanager/routes.py b/taskmanager/routes.py index a491f5a..252e07c 100644 --- a/taskmanager/routes.py +++ b/taskmanager/routes.py @@ -26,31 +26,31 @@ def addtask(): username = request.form['username'] # Input sanitation if not taskname.isalnum(): - return "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 "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 taskdesc.isprintable(): - return "Task description has to be made of printable characters." + return render_template('response.html', response = "Task description has to be made of printable characters.") if len(taskname) < 1 or len(taskname) > 40: - return "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 "Task description lenght invalid, only smaller then 2000 charachters allowed" + return render_template('response.html', response = "Task description lenght invalid, only smaller then 2000 charachters allowed") if username == "": creatorid = None else: try: creatorid = User.query.filter_by(username = username).first().id except: - return 'No user with this username. Please register.' + return render_template('response.html', response = 'No user with this username. Please register.') if creatorid is None: - return 'No user with this username. Please register.' + return render_template('response.html', response = 'No user with this username. Please register.') sqladdtask = Task(name = taskname, desc = taskdesc, creatorid = creatorid) try: db.session.add(sqladdtask) db.session.commit() - return 'Task added' + return render_template('response.html', response = 'Task added') except: - return 'Adding task failed' + return render_template('response.html', response = 'Adding task failed') @app.route('/register', methods=['POST', 'GET']) def register(): @@ -61,27 +61,27 @@ def register(): contact = request.form['contact'] password = request.form['password'] if not username.isalnum(): - return "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 "Contact information has to be made of printable characters." + return render_template('response.html', response = "Contact information has to be made of printable characters.") if not password.isprintable(): - return "Password has to be made of printable characters." + return render_template('response.html', response = "Password has to be made of printable characters.") if len(username) < 1 or len(username) > 40: - return "Username lenght invalid, only smaller then 40 charachters allowed" + return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed") if len(contact) > 100: - return "Contact lenght invalid, only smaller then 100 charachters allowed" + return render_template('response.html', response = "Contact lenght invalid, only smaller then 100 charachters allowed") if len(password) > 500: - return "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) try: db.session.add(sqladduser) db.session.commit() - return 'User added' + return render_template('response.html', response = 'User added') except: - return 'Adding user failed' + return render_template('response.html', response = 'Adding user failed') else: - return 'HTTP request method not recogniezed' + return render_template('response.html', response = 'HTTP request method not recogniezed') @app.route('/projects/', methods=['GET','POST']) @@ -89,63 +89,70 @@ def project(task_id:int): try: task = Task.query.get(task_id) except: - return 'Task not found, bad URL' + return render_template('response.html', response = 'Task not found, bad URL') if task is None: - return 'Task not found, bad URL' + return render_template('response.html', response = 'Task not found, bad URL') users = gettaskusers(task_id) if request.method == 'GET': return render_template("project.html", task = task, users = users) elif request.method == 'POST': username = request.form['username'] if len(username) < 1 or len(username) > 40: - return "Username lenght invalid, only smaller then 40 charachters allowed" + return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed") for user in users: if username == user.username: - return 'User already added to task' + return render_template('response.html', response = 'User already added to task') try: userid = User.query.filter_by(username = username).first().id except: - return 'User not found, please register.' + return render_template('response.html', response = 'User not found, please register.') if userid is None: - return 'User not found, please register.' + return render_template('response.html', response = 'User not found, please register.') sqladduser = TaskUser(userid = userid, taskid = task_id) try: db.session.add(sqladduser) db.session.commit() - return 'User added' + return render_template('response.html', response = 'User added') except: - return 'Adding user failed' + return render_template('response.html', response = 'Adding user failed') @app.route('/projects//del', methods=['GET','POST']) def deltask(task_id:int): try: task = Task.query.get(task_id) except: - return 'Task not found, bad URL' + return render_template('response.html', response = 'Task not found, bad URL') + try: + taskusers = TaskUser.query.filter_by(task_id = task_id) + except: + taskusers = None if task is None: - return 'Task not found, bad URL' + return render_template('response.html', response = 'Task not found, bad URL') creatorid = task.creatorid if request.method == 'GET': if creatorid is None: try: db.session.delete(task) db.session.commit() - return 'Task deleted' + if taskusers != None: + db.session.delete(taskusers) + db.session.commit() + return render_template('response.html', response = 'Task deleted') except: - return 'Deleting task failed' + return render_template('response.html', response = 'Deleting task failed') else: return render_template('deltask.html', task = task) if request.method == 'POST': password = request.form['password'] if len(password) < 1 or len(password) > 500: - return "Password lenght invalid, only smaller then 500 charachters allowed" + return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed") # Check password if password != ADMINPASS and password != User.query.get(creatorid).password: - return 'Wrong password' + return render_template('response.html', response = 'Wrong password') # Delete task try: db.session.delete(task) db.session.commit() - return 'Task deleted' + return render_template('response.html', response = 'Task deleted') except: - return 'Deleting task failed' + return render_template('response.html', response = 'Deleting task failed') diff --git a/taskmanager/templates/response.html b/taskmanager/templates/response.html new file mode 100644 index 0000000..e62e36a --- /dev/null +++ b/taskmanager/templates/response.html @@ -0,0 +1,26 @@ + + + + + + + {{task.name}} + + +
+ +
+
+
+

{{response}}

+
+
+ + +