-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
188 lines (163 loc) · 5.48 KB
/
application.py
File metadata and controls
188 lines (163 loc) · 5.48 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from flask import Flask, render_template, redirect, request, session, Markup
import mysql.connector
import HTML
app = Flask(__name__)
cnx = mysql.connector.connect(
user='root',
password='go away plz',
host='localhost',
database='self',
buffered=True)
cursor = cnx.cursor()
signInError = 'false'
from random import randint
class MyClass:
i = 12345
def f(self):
z = randint(1,50)
return z
@app.route('/devfest')
def devfest():
return redirect('http://devfe.st/')
@app.route('/signup')
def signup():
return render_template('signup.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/signin')
def signin():
if 'username' in session:
return render_template('dashboard.html', name = session['username'])
if request.method == 'GET':
return render_template('signin.html', error = signInError)
elif request.method == 'POST':
username = request.form['username']
password = request.form['password']
query = "SELECT user_name, user_password FROM user"
cursor.execute(query)
found = False
for(user_name, user_password) in cursor:
if username == user_name:
found = True
if password == user_password:
session['username'] = username
return redirect('/')
else:
print "Wrong password"
return redirect('/signin')
print "Username not found"
return redirect('/signin')
@app.route('/')
def index():
if 'username' in session:
# return render_template('dashboard.html', name = session['username'])
return redirect('/dashboard')
return redirect('/login')
@app.route('/index')
def home():
if 'username' in session:
return render_template('dashboard.html', name = session['username'])
return redirect('/login')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('login.html')
elif request.method == 'POST':
username = request.form['username']
password = request.form['password']
query = "SELECT user_name, user_password FROM user"
cursor.execute(query)
found = False
for(user_name, user_password) in cursor:
if username == user_name:
found = True
if password == user_password:
session['username'] = username
signInError = 'display:none'
return redirect('/')
else:
print "Wrong password"
signInError = 'false'
return redirect('/signin')
print "Username not found"
return redirect('/signin')
@app.route('/dashboard', methods=['GET', 'POST'])
def dashboard():
if request.method == 'GET':
query = "SELECT user_id FROM user WHERE user_name=\"%s\"" % session['username']
cursor.execute(query)
for(user_id) in cursor:
query = "SELECT * FROM tasks where user_id=%d" % user_id[0]
cursor.execute(query)
count = 0
t = HTML.Table(header_row=['Task Title', 'Task Description'])
for (user_id, task_title, task_description) in cursor:
if count==3 or not task_title or not task_description:
break;
count=count+1
t.rows.append([task_title, task_description])
html = str(t)
value = Markup(html)
query = "SELECT user_id FROM user WHERE user_name=\"%s\"" % session['username']
cursor.execute(query)
for(user_id) in cursor:
query = "SELECT * FROM rewards WHERE user_id=%d" % user_id[0]
cursor.execute(query)
count = 0
t2 = HTML.Table(header_row=['Reward Title', 'Reward Description'])
for (user_id, reward_title, reward_description) in cursor:
if count==3 or not reward_title or not reward_description:
break;
count=count+1
t2.rows.append([reward_title, reward_description])
html2 = str(t2)
value2 = Markup(html2)
return render_template('dashboard.html', name=session['username'], mytaskstable=value, myrewardstable=value2)
@app.route('/reporttask', methods=['GET','POST'])
def reporttask():
if request.method=='POST':
task_title = request.form['task_title']
task_description = request.form['task_description']
if not task_title or not task_description:
return redirect('/')
query = "SELECT user_id FROM user WHERE user_name=\"%s\"" % session['username']
cursor.execute(query)
for(user_id) in cursor:
query = "INSERT INTO tasks (user_id, task_title, task_description) VALUES (%d, \"%s\", \"%s\")" % (user_id[0], task_title, task_description)
cursor.execute(query)
cnx.commit()
return redirect('/dashboard')
@app.route('/reportreward', methods=['GET','POST'])
def reportreward():
if request.method=='POST':
reward_title = request.form['reward_title']
reward_description = request.form['reward_description']
if not reward_title or not reward_description:
return redirect('/')
query = "SELECT user_id FROM user WHERE user_name=\"%s\"" % session['username']
cursor.execute(query)
for(user_id) in cursor:
query = "INSERT INTO rewards (user_id, reward_title, reward_description) VALUES (%d, \"%s\", \"%s\")" % (user_id[0], reward_title, reward_description)
cursor.execute(query)
cnx.commit()
return render_template('dashboard.html', name = session['username'])
# @app.route('/viewtask')
# def viewtask():
#Code to view the tasks page here.
# if request.method == 'GET':
@app.route('/stats')
def stats():
x = MyClass()
#return render_template('stats.html', name = session['username'])
return render_template('stats.html', name = x.f())
@app.route('/logout')
def logout():
session.pop('username', None)
return redirect('/login')
if __name__ == '__main__':
app.debug = True
app.secret_key = 'l34GE0q1l1U+4D8c4S/1Yg=='
app.run()
cursor.close()
cnx.close()