forked from Decentrala/taskmanager
add response.html and deleting user assignment to deleted tasks
This commit is contained in:
parent
4911842d3f
commit
673c04af19
@ -8,4 +8,4 @@ Depends: gunicorn, python3-flask-sqlalchemy
|
||||
Homepage: https://gitea.dmz.rs/Decentrala/taskmanager
|
||||
Maintainer: Decentrala <dmz@dmz.rs>
|
||||
Description: Interactive TODO list Web app
|
||||
Version: 1.0.6
|
||||
Version: 1.0.7
|
||||
|
@ -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 <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:
|
||||
return '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>.')
|
||||
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/<int:task_id>', 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 <a href="/register">register</a>.'
|
||||
return render_template('response.html', response = 'User not found, please <a href="/register">register</a>.')
|
||||
if userid is None:
|
||||
return 'User not found, please <a href="/register">register</a>.'
|
||||
return render_template('response.html', response = 'User not found, please <a href="/register">register</a>.')
|
||||
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/<int:task_id>/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')
|
||||
|
26
taskmanager/templates/response.html
Normal file
26
taskmanager/templates/response.html
Normal file
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="stylesheet" href="/static/style.css" />
|
||||
<title>{{task.name}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="container">
|
||||
<ul>
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="/register">Register</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="container page page-project">
|
||||
<section >
|
||||
<h1>{{response}}</h1>
|
||||
</section>
|
||||
</main>
|
||||
<footer>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user