-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (47 loc) · 1.95 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from datetime import datetime
import os
from flask import Flask, render_template, request, redirect, url_for, session
from passlib.hash import pbkdf2_sha256
from model import Task, User
app = Flask(__name__)
@app.route('/all')
def all_tasks():
return render_template('all.jinja2', tasks=Task.select())
@app.route('/incomplete', methods=['GET', 'POST'])
def incomplete_tasks():
if 'username' not in session:
return redirect(url_for('login'))
if request.method == 'POST':
user = User.select().where(User.name == session['username']).get()
Task.update(performed=datetime.now(), performed_by=user)\
.where(Task.id == request.form['task_id'])\
.execute()
return render_template('incomplete.jinja2', tasks=Task.select().where(Task.performed.is_null()))
@app.route('/create', methods=['GET', 'POST'])
def create():
if 'username' not in session:
return redirect(url_for('login'))
if request.method == 'POST':
task = Task(name=request.form['name'])
task.save()
return redirect(url_for('all_tasks'))
else:
return render_template('create.jinja2')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
user = User.select().where(User.name == request.form['name']).get()
if user and pbkdf2_sha256.verify(request.form['password'], user.password):
session['username'] = request.form['name']
return redirect(url_for('all_tasks'))
return render_template('login.jinja2', error="Incorrect username or password.")
else:
return render_template('login.jinja2')
@app.route('/logout')
def logout():
session.pop('username', None)
return redirect(url_for('all_tasks'))
app.secret_key = b'\x9d\xb1u\x08%\xe0\xd0p\x9bEL\xf8JC\xa3\xf4J(hAh\xa4\xcdw\x12S*,u\xec\xb8\xb8'
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)