diff --git a/taskmanager/config.ini b/taskmanager/config.ini new file mode 100644 index 0000000..9dcd9d5 --- /dev/null +++ b/taskmanager/config.ini @@ -0,0 +1,2 @@ +[credentials] +ADMINPASS = defaultpassword diff --git a/taskmanager/models.py b/taskmanager/models.py index 2972b30..9c9b49a 100644 --- a/taskmanager/models.py +++ b/taskmanager/models.py @@ -4,6 +4,7 @@ class Task(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) desc = db.Column(db.String, nullable=True) + creatorid = db.Column(db.Integer, nullable=True) class User(db.Model): id = db.Column(db.Integer, primary_key=True) diff --git a/taskmanager/routes.py b/taskmanager/routes.py index c911756..e4da4d1 100644 --- a/taskmanager/routes.py +++ b/taskmanager/routes.py @@ -2,6 +2,15 @@ from flask import render_template, request, redirect from taskmanager import app, db from taskmanager.functions import * from taskmanager.models import * +import configparser + +#CONFIG_PATH = "/var/taskmanager/taskmanager/config.ini" +CONFIG_PATH = "/home/anon/src/taskmanager/taskmanager/config.ini" + +config = configparser.ConfigParser() +config.read(CONFIG_PATH) + +ADMINPASS = config.get('credentials', 'ADMINPASS') @app.route('/', methods=['GET']) def index(): @@ -15,7 +24,17 @@ def addtask(): elif request.method == 'POST': taskname = request.form['taskname'] taskdesc = request.form['taskdesc'] - sqladdtask = Task(name = taskname, desc = taskdesc) + username = request.form['username'] + if username == "": + creatorid = None + else: + try: + creatorid = User.query.filter_by(username = username).first().id + except: + return 'No user with this username. Please register.' + if creatorid is None: + return 'No user with this username. Please register.' + sqladdtask = Task(name = taskname, desc = taskdesc, creatorid = creatorid) try: db.session.add(sqladdtask) db.session.commit() @@ -45,12 +64,14 @@ def register(): @app.route('/projects/', methods=['GET','POST']) def project(task_id:int): + try: + task = Task.query.get(task_id) + except: + return 'Task not found, bad URL' + if task is None: + return 'Task not found, bad URL' users = gettaskusers(task_id) if request.method == 'GET': - try: - task = Task.query.get(task_id) - except: - return 'Task not found, bad URL' return render_template("project.html", task = task, users = users) elif request.method == 'POST': username = request.form['username'] @@ -60,6 +81,8 @@ def project(task_id:int): userid = User.query.filter_by(username = username).first().id except: return 'User not found, please register.' + if userid is None: + return 'User not found, please register.' sqladduser = TaskUser(userid = userid, taskid = task_id) try: db.session.add(sqladduser) @@ -68,3 +91,34 @@ def project(task_id:int): except: return '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' + if task is None: + return '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' + except: + return 'Deleting task failed' + else: + return render_template('deltask.html', task = task) + if request.method == 'POST': + password = request.form['password'] + # Check password + if password != ADMINPASS and password != User.query.get(creatorid).password: + return 'Wrong password' + # Delete task + try: + db.session.delete(task) + db.session.commit() + return 'Task deleted' + except: + return 'Deleting task failed' diff --git a/taskmanager/templates/addtask.html b/taskmanager/templates/addtask.html index 95fbd3f..a36d042 100644 --- a/taskmanager/templates/addtask.html +++ b/taskmanager/templates/addtask.html @@ -25,7 +25,11 @@
- + +
+
+ +
diff --git a/taskmanager/templates/deltask.html b/taskmanager/templates/deltask.html new file mode 100644 index 0000000..1272bbf --- /dev/null +++ b/taskmanager/templates/deltask.html @@ -0,0 +1,34 @@ + + + + + + + Delete task + + +
+ +
+
+

Create new task

+
+
+

Task creator's password

+

+ + +
+
+ +
+
+ +
+ + diff --git a/taskmanager/templates/project.html b/taskmanager/templates/project.html index 653c294..a7e7809 100644 --- a/taskmanager/templates/project.html +++ b/taskmanager/templates/project.html @@ -43,6 +43,7 @@
+

DELETE TASK