/
admin.py
145 lines (129 loc) · 4.88 KB
/
admin.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
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
import sqlite3
import bottle_session
import bottle
from datetime import time, datetime, date
from bottle import route, run, template, request, static_file, get, redirect
import string
from random import *
adminSession = ""
get('/<filename:re:.*\.*>')
def server_static(filename):
return static_file(filename, root='./static/')
@route('/logout')
def logout():
session = bottle.request.environ.get('beaker.session')
session['sp_user'] = ''
session['usertype'] = ''
return redirect('/')
def getSession():
session = bottle.request.environ.get('beaker.session')
if(session != ""):
return session.get('sp_user')
else:
return ""
def adminHome(session):
checkSession()
loggedinUser = getSession()
return template('adminHome', values=[loggedinUser], menu=[""], dininglocation={}, diningdetails=[])
def checkSession():
session = bottle.request.environ.get('beaker.session')
if(session.get('sp_user') == "" or session.get('sp_user') == None or session.get('usertype')!="ADM"):
return redirect("/")
else:
return ""
@route("/addLocation", method="GET")
def addLocation():
checkSession()
loggedinUser = getSession()
connection = sqlite3.connect('ShiftPlanner.db')
cursor = connection.cursor()
cursor.execute('SELECT * FROM DiningLocation')
result = cursor.fetchall()
cursor.close()
diningdetails = {}
for row in result:
diningdetails[row[0]] = row[1]
return template('adminHome', values=[loggedinUser], menu=["addLocation"], dininglocation=diningdetails, diningdetails=[])
@route("/addManager", method="GET")
def addmanager():
checkSession()
loggedinUser = getSession()
connection = sqlite3.connect('ShiftPlanner.db')
cursor = connection.cursor()
cursor.execute('SELECT * FROM DiningLocation')
result = cursor.fetchall()
cursor.close()
managerdetails = {}
for row in result:
managerdetails[row[0]] = row[1]
return template('adminHome', values=[loggedinUser], menu=["addManager"], dininglocation=managerdetails, diningdetails=[])
@route("/viewLocations", method="GET")
def viewLocation():
checkSession()
loggedinUser = getSession()
connection = sqlite3.connect('ShiftPlanner.db')
cursor = connection.cursor()
cursor.execute('SELECT * FROM DiningLocation')
result = cursor.fetchall()
cursor.close()
return template('adminHome', values=[loggedinUser], menu=["viewLocations"], dininglocation={}, diningdetails=result)
@route("/addManager", method="POST")
def addManager_todb():
checkSession()
loggedinUser = getSession()
userid = request.POST.get('userid','').strip()
name = request.POST.get('name','').strip()
email = request.POST.get('email', '').strip()
contactnumber = request.POST.get('contactnumber','').strip()
locationid = request.POST.get('dininglocation','').strip()
usertype = "MGR"
activate = 1
chars = string.ascii_letters + string.digits
password = ""
for x in range(randint(6,8)):
password += choice(chars)
print(password)
connection = sqlite3.connect('ShiftPlanner.db')
inserted = 1
try:
connection.execute('INSERT INTO UserInformation(UserID, Name, Email, ContactNumber, CreatedDate) VALUES(?,?,?,?,?)', (int(userid), name, email, int(contactnumber), datetime.now()))
connection.execute('INSERT INTO UserLogin(UserEmail, Password, UserType, IsActive, LastLogin) VALUES(?,?,?,?,?)', (email, password, usertype, activate, datetime.now()))
connection.execute('INSERT INTO UserDiningLocation(UserID, DiningLocationID) VALUES(?,?)', (userid, locationid))
connection.commit()
except Exception as err:
print(err)
inserted = -1
cursor = connection.cursor()
cursor.execute('SELECT Name, Email, ContactNumber FROM UserInformation')
result = cursor.fetchall()
cursor.close()
managerdetails = {}
for row in result:
managerdetails[row[0]] = row[1]
return template('adminHome', values=[loggedinUser, inserted], menu=["addManager"], dininglocation=managerdetails, diningdetails=[])
@route("/addLocation", method="POST")
def addLocation_todb():
checkSession()
loggedinUser = getSession()
diningname = request.POST.get('diningname','').strip()
address = request.POST.get('address','').strip()
city = request.POST.get('city','').strip()
state = request.POST.get('state','').strip()
zipcode = request.POST.get('zipcode','').strip()
contactnumber = request.POST.get('contactNumber','').strip()
connection = sqlite3.connect('ShiftPlanner.db')
inserted = 1
try:
connection.execute('INSERT INTO DiningLocation(Name, Address, City, State, Zipcode, ContactNumber, IsActive) VALUES(?,?,?,?,?,?,?)', (diningname, address, city, state, (int(zipcode)), (int(contactnumber)), 1))
connection.commit()
except Exception as err:
print(err)
inserted = -1
cursor = connection.cursor()
cursor.execute('SELECT LocationID, Name FROM DiningLocation')
result = cursor.fetchall()
cursor.close()
diningdetails = {}
for row in result:
diningdetails[row[0]] = row[1]
return template('adminHome', values=[loggedinUser, inserted], menu=["addLocation"], dininglocation=diningdetails, diningdetails=[])