-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
113 lines (98 loc) · 3.93 KB
/
app.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from flask import Flask
from flask import render_template,session,redirect,request,url_for
import urllib2
import sqlite3
import login
app=Flask(__name__)
app.secret_key = "PTC"
registeredteacherlist = ["Zamansky, Mike", "Brownmykolyk, Topher", "Brooks, Peter", "Cocoros, Jim"]
zparents = ["p1","p2","p3","p4","p5"]
def isLoggedIn():
if "username" in session:
return True
else:
return False
def getUsername():
return session["username"]
@app.route('/',methods=["POST","GET"])
def home():
if request.method == 'GET':
return render_template("index.html")
@app.route('/parentlogin',methods=["POST","GET"])
def pl():
if request.method == 'GET':
return render_template("parentlogin.html")
else:
usern = request.form['username'].encode('ascii','ignore')
passw = request.form['password'].encode('ascii','ignore')
if login.loginParent(usern,passw):
session['username'] = usern
return redirect ("/parentpostlogin")
else:
return redirect ("/parentlogin")
@app.route('/teacherlogin',methods=["POST","GET"])
def tl():
if request.method == 'GET':
return render_template("teacherlogin.html")
else:
usern = request.form['username'].encode('ascii','ignore')
passw = request.form['password'].encode('ascii','ignore')
if login.loginTeacher(usern,passw):
session['username'] = usern
return redirect ("/teacherpostlogin")
else:
return redirect ("/teacherlogin")
@app.route('/parentregister',methods=["POST","GET"])
def pr():
if request.method == 'GET':
return render_template("parentregister.html")
else:
usern = request.form["username"].encode('ascii','ignore')
passw = request.form["password"].encode('ascii','ignore')
child = request.form["child"].encode('ascii','ignore')
name = request.form["parent"].encode('ascii','ignore')
digit = request.form["id"].encode('ascii','ignore')
login.registerParent(usern, passw, child, name, digit)
return redirect('/parentlogin')
@app.route('/teacherregister',methods=["POST","GET"])
def tr():
if request.method == 'GET':
return render_template("teacherregister.html")
else:
usern = request.form["username"].encode('ascii','ignore')
passw = request.form["password"].encode('ascii','ignore')
subject = request.form["subject"].encode('ascii','ignore')
room = request.form["room"].encode('ascii','ignore')
teacher = request.form["teacher"].encode('ascii','ignore')
veri = request.form["zamansky"].encode('ascii','ignore')
login.registerTeacher(usern, passw, subject, room, teacher, veri)
return redirect('/teacherlogin')
@app.route('/parentpostlogin',methods=["POST","GET"])
def ppl():
#IMPORTANT, implement a check for login so that people cannot just type in the url! Implement after this page is done
if request.method == 'GET':
if isLoggedIn():
return render_template("parentpostlogin.html", teacher = registeredteacherlist, length = len(registeredteacherlist), name = login.getParentName(getUsername()))
return redirect ('/')
else:
return redirect ('/chooser')
@app.route('/teacherpostlogin',methods=["POST","GET"])
def tpl():
#IMPORTANT, implement a check for login so that people cannot just type in the url! Implement after this page is done
if request.method == 'GET':
if isLoggedIn():
return render_template("teacherpostlogin.html", zparents = zparents, length = len(zparents), name = login.getTeacherName(getUsername()))
else:
return redirect ('/')
@app.route('/logout',methods=["POST","GET"])
def logout():
if request.method == 'GET':
session.pop('username', None)
return redirect("/")
@app.route('/chooser', methods = ["POST","GET"])
def chooser():
if isLoggedIn():
return render_template ('chooser.html', teacher = registeredteacherlist, length = len(registeredteacherlist), name = login.getParentName(getUsername()))
return redirect ('/')
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port =7769)