-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.py
More file actions
409 lines (326 loc) · 11.6 KB
/
user.py
File metadata and controls
409 lines (326 loc) · 11.6 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
from flask import Flask,render_template,request
import sqlite3 as sql
import os
app=Flask(__name__)
@app.route('/') #homepage
def home():
return render_template('friends.html')
@app.route('/adminback') #homepage
def homeadmin():
return render_template('admin.html')
@app.route('/logout') #homepage
def logout():
msg="Logged out sucessfully"
return render_template('result2.html',msg=msg)
@app.route('/visitor') #homepage
def visitor():
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select *from genrestable4')
rows=cur.fetchall();
return render_template('homepage.html',rows=rows)
@app.route('/loggeduser/<username>') #homepage
def loggeduser(username):
return render_template('aftersignin.html',username=username)
@app.route('/login') #homepage
def login():
return render_template('login.html')
@app.route('/userlogin/<username>') #homepage
def userlogin(username):
return render_template('aftersignin.html',username=username)
@app.route('/signin',methods=['POST','GET']) #homepage
def signin():
if request.method=='POST':
username=request.form['username']
password=request.form['password']
con=sql.connect('database.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select username,password from users1')
rows=cur.fetchall();
for row in rows:
if(row["username"]==username and row["password"] ==password):
return render_template('aftersignin.html',username=username)
return render_template('login.html')
@app.route('/forgetpassword') #homepage
def forgetpassword():
return render_template('updatepassword.html')
@app.route('/updatepassword',methods=['POST','GET']) #homepage
def updatepassword():
if request.method=='POST':
username=request.form['username']
con=sql.connect('database.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select username from users1')
rows=cur.fetchall();
for row in rows:
if(row["username"]==username):
return render_template('upadateform.html',username=username)
return render_template('updatepassword.html')
@app.route('/updatepassword2',methods=['POST','GET']) #homepage
def updatepassword2():
if request.method=='POST':
username=request.form['username']
password=request.form['password']
con=sql.connect('database.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('Update users1 set password= ? where username= ? ',(password,username,))
msg="Password sucessfully Updated"
return render_template('updatesucessfull.html',msg=msg)
@app.route('/adminbackhome') #homepage
def homeadminback():
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select *from genrestable4')
rows=cur.fetchall();
return render_template('list2.html',rows=rows)
@app.route('/homepage') # for visitor show genere list
def homepage():
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select *from genrestable4')
rows=cur.fetchall();
return render_template('homepage.html',rows=rows)
@app.route('/newgenre') # Add new genere
def new_genre():
return render_template('genres.html')
@app.route('/addshow',methods=['POST','GET']) #On submit store it to the database
def addshow():
if request.method=='POST':
#try:
genre=request.form['genre']
ID=request.form['ID']
with sql.connect('database2.db')as con:
cur=con.cursor()
#cur.execute('INSERT INTO genres(genre) VALUES(?)',(genre))
cur.execute('INSERT INTO genrestable4(ID,genre) VALUES(?,?)',(ID,genre))
con.commit()
msg="New genre added sucessfully"
return render_template('result.html',msg = msg)
con.close()
@app.route('/newshow') #Add a new show
def newshow():
return render_template('shows.html')
@app.route('/showlistnow/<msg>') #Add a new show
def showlist(msg):
if(msg=="Big_Bang_Theory"):
return render_template('bbt.html')
elif(msg=="Games_of_thrones"):
return render_template('got.html')
elif(msg=="Friends"):
return render_template('friends2.html')
elif(msg=="How_I_met_your_mother"):
return render_template('himym.html')
elif(msg=="13_Reasons_why"):
return render_template('13reasons.html')
elif(msg=="Lost"):
return render_template('lost.html')
elif(msg=="Breaking_Bad"):
return render_template('bb.html')
elif(msg=="Flash"):
return render_template('flash.html')
elif(msg=="Sherlock_Homes"):
return render_template('sher.html')
elif(msg=="Supernatural"):
return render_template('supernatural.html')
@app.route('/addnewshow',methods=['POST','GET']) # On submit store it the database
def addnewshow():
if request.method=='POST':
#try:
gid=request.form['g_id']
sid=request.form['s_id']
sname=request.form['showname']
rating=request.form['rating']
suggestions=request.form['suggestions']
with sql.connect('database2.db')as con:
cur=con.cursor()
#cur.execute('INSERT INTO genres(genre) VALUES(?)',(genre))
cur.execute('INSERT INTO showlist2(g_id,s_id,sname,rating,suggestions) VALUES(?,?,?,?,?)',(gid,sid,sname,rating,suggestions))
con.commit()
msg="New show added sucessfully"
return render_template('result.html',msg = msg)
@app.route('/enternew') # open new registration page
def new_student():
return render_template('user.html')
@app.route('/addrec',methods=['POST','GET']) # on submit store it to the databse
def addrec():
if request.method=='POST':
#try:
username=request.form['username']
email=request.form['email']
first_name=request.form['first_name']
last_name=request.form['last_name']
dob=request.form['dob']
pwd=request.form['pwd']
activity=request.form['activity']
with sql.connect('database.db')as con:
cur=con.cursor()
cur.execute('INSERT INTO users1(username,email,firstname,lastname,dob,password,activity) VALUES(?,?,?,?,?,?,?)',(username,email,first_name,last_name,dob,pwd,activity))
con.commit()
msg="User account created sucessfully"
return render_template('result2.html',msg = msg)
con.close()
@app.route('/newpage/<msg>') # Show all the list of the show to the user without delete button
def new_page(msg):
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select * from showlist2 where g_id= ?',(msg,))
rows=cur.fetchall();
return render_template('newpage.html',rows=rows)
@app.route('/showlist/<msg>') # Show all the list of the show to the user with delete button
def new_page2(msg):
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select *from showlist2 where g_id= ?',(msg,))
rows=cur.fetchall();
return render_template('newpage2.html',rows=rows)
@app.route('/admin') #homepage login
def admin():
return render_template('adminlogin.html')
@app.route('/adminlogin',methods=['GET','POST']) #homepage admin
def adminlogin():
if request.method=='POST':
password=request.form['password']
if(password=='password'):
return render_template('admin.html')
@app.route('/list') # List all the generes to the admin
def listgenere():
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select *from genrestable4')
rows=cur.fetchall();
return render_template('list2.html',rows=rows)
@app.route('/listgenereuser/<msg>') # List all the generes to the user
def listgenereuser(msg):
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select ID,genre from genrestable4')
rows=cur.fetchall();
return render_template('list3.html',rows=rows,msg1=msg)
@app.route('/showlistuser/<msg>/<msg1>') # Show all the list of the show to the user with delete button
def new_page3(msg,msg1):
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select s_id,sname from showlist2 where g_id= ?',(msg,))
rows=cur.fetchall();
return render_template('newpage3.html',rows=rows,msg1=msg1)
@app.route('/rateshow/<msg>/<msg1>/<msg2>') # List all the generes to the admin
def rateshow(msg,msg1,msg2):
return render_template('rateshow.html',msg=msg,msg1=msg1,msg2=msg2)
@app.route('/rateshowsubmit/<msg1>',methods=['GET','POST'])
def rateshowsubmit(msg1):
if request.method=='POST':
sid=request.form['s_id']
sname=request.form['sname']
uname=request.form['uname']
ratings=request.form['sratings']
comments=request.form['comments']
with sql.connect('database2.db')as con:
cur=con.cursor()
#cur.execute('INSERT INTO genres(genre) VALUES(?)',(genre))
cur.execute('INSERT INTO usercomment3(sid,sname,uname,rating,comments) VALUES(?,?,?,?,?)', (sid,sname,uname,ratings,comments))
msg="Your Ratings has been recorded sucesfully !!"
con.commit()
return render_template('commentadded.html',msg = msg,msg1=msg1)
@app.route('/deleteshow/<ID>') # Delete the selected genere (for admin)
def deleteshow(ID):
try:
with sql.connect('database2.db')as con:
cur=con.cursor()
cur.execute('DELETE from genrestable4 where ID= ?',(ID,))
con.commit()
msg="Record sucessfully deleted sucessfully"
finally:
con.row_factory=sql.Row
cur=con.cursor()
cur.execute('select * from genrestable4')
rows=cur.fetchall();
return render_template('list2.html',rows=rows)
con.close()
@app.route('/deleteshowlist/<ID>/<ID2>') # Delete the selected show (for admin)
def deleteshowlist(ID,ID2):
try:
with sql.connect('database2.db')as con:
cur=con.cursor()
cur.execute('DELETE from showlist2 where s_id= ? and g_id= ?',(ID,ID2,))
con.commit()
msg="record sucessfully deleted"
finally:
con.row_factory=sql.Row
cur=con.cursor()
cur.execute('select * from showlist2')
rows=cur.fetchall();
return render_template('newpage2.html',rows=rows)
con.close()
@app.route('/deleteuser/<ID>') # Delete the selected user (for admin)
def deleteuserlist(ID):
try:
with sql.connect('database.db')as con:
cur=con.cursor()
cur.execute('DELETE from users1 where username= ?',(ID,))
con.commit()
msg="record sucessfully deleted"
finally:
con.row_factory=sql.Row
cur=con.cursor()
cur.execute('select * from users1')
rows=cur.fetchall();
return render_template('list.html',rows=rows)
con.close()
@app.route('/deletecomment/<ID>/<msg>') # Delete the selected user (for admin)
def deletecomment(ID,msg):
try:
with sql.connect('database2.db')as con:
cur=con.cursor()
cur.execute('DELETE from usercomment3 where sname= ?',(ID,))
con.commit()
finally:
con.row_factory=sql.Row
cur=con.cursor()
cur.execute('select * from usercomment3')
rows=cur.fetchall();
return render_template('usercommenttableshow.html',rows=rows,msg=msg)
con.close()
@app.route('/userdetails') # show all the user details
def list():
con=sql.connect('database.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select *from users1')
rows=cur.fetchall();
return render_template('list.html',rows=rows)
@app.route('/listusercomments/<msg>') # show all the user details
def listcomments(msg):
con=sql.connect('database2.db')
con.row_factory = sql.Row
cur=con.cursor()
cur.execute('select *from usercomment3 where uname= ?',(msg,))
rows=cur.fetchall();
return render_template('usercommenttableshow.html',rows=rows,msg=msg)
@app.route('/got') #homepage
def got():
return render_template('got.html')
@app.route('/hiym') #homepage
def friends():
return render_template('himym.html')
@app.route('/sh') #homepage
def sh():
return render_template('sher.html')
@app.route('/thr') #homepage
def thr():
return render_template('13reasons.html')
@app.route('/bb') #homepage
def bb():
return render_template('bb.html')
if __name__=='__main__':
app.run(debug=True)