-
Notifications
You must be signed in to change notification settings - Fork 1
/
account.py
185 lines (160 loc) · 7.38 KB
/
account.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
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
from memory import Memory
from Course import Course
classlist = []
amtClass = 0
class Account:
def __init__(self, username, password, name, address, email, phonenumber, accountFlag):
# for accountFlag: 0 is supervisor, 1 is administrator, 2 is instructor, 3 is TA
self.username = username
self.password = password
self.name = name
self.address = address
self.email = email
self. phonenumber = phonenumber
self.accountFlag = accountFlag
#creates a new class, passes a string list that contains the instructor name
#increments the amtClass variable so overwriting classlist courses is avoided if something in middle is removed
def createClass(self, stringList):
global amtClass
try:
classlist.append(Course(amtClass, stringList[1]))
except:
print("Command received, class name invalid")
return
amtClass += 1
#deletes class at the number given when commanded
def deleteClass(self, stringList):
global amtClass
try:
classlist.remove(classlist[int(stringList[1])])
except:
print("IndexError: List index out of range: tried to delete a class that doesnt exit")
def assign_instructor_class(self, stringList):
try:
classlist[int(stringList[2])].setInstructor(stringList[1])
except:
print("Error: cant assign instructor to class")
def unassign_instructor_class(self, stringList):
try:
classlist[int(stringList[1])].setInstructor("No Instructor")
except:
print("Error: cant remove instructor from that class please retry")
def assign_TA_class(self, stringList):
try:
classlist[int(stringList[2])].setTA(stringList[1])
except:
print("Error Assign TA: TA failed to be assigned")
def unassign_TA_class(self, stringList):
try:
classlist[int(stringList[1])].setTA("No TA")
except:
print("Failed to remove TA from class")
def printAllClasses(self, stringlist):
for x in range(0, len(classlist)):
print(classlist[x].printInfo())
def create_account(self, stringList):
# must have the right amount of arguments
if stringList.amount() != 7:
raise Exception("Account Creation Error: Wrong amount of information passed")
return
# must have the right account permissions
if self.accountFlag != 0:
raise Exception("Account Creation Error: You don't have permission")
return
# last variable in stringList should be a number between 0-3
if stringList[7] is not int:
raise Exception("Account Creation Error: Wrong account type")
return
# account flag must be 0-3
if stringList[7]<0 or stringList>3:
raise Exception("Account Creation Error: Invalid permissions given")
return
# check if passed account flag is correct
if stringList[7] is int and stringList[7]<0 or stringList[7]>3:
raise Exception("Account Creation Error: Invalid account type")
return
# call constructor with correct information
newAccount = Account(stringList[0], stringList[1], stringList[2], stringList[3], stringList[4], stringList[5], stringList[6])
# write it to memory
Memory.write_account(newAccount)
return
def delete_account(self, stringList):
# must have the right amount of arguments
if stringList.amount() != 1:
raise Exception("Account Deletion Error: Wrong amount of information passed")
return
# must have the right account permissions
if self.accountFlag != 0:
raise Exception("Account Deletion Error: You don't have permission")
return
# username must be a str
if stringList[0] is not str:
raise Exception("Account Deletion Error: Incorrect username")
return
# deletes account from memory
Memory.delete_account(stringList[0])
return
# edit methods work for both admin/supervisor edits and self edits
# stringList[0] = username, stringList[1] = updated_name
def edit_account_password(self, string_list):
if self.username == string_list[0] or self.accountFlag == 0 or self.accountFlag == 1:
if self.password == string_list[1]:
print("it is the current password")
elif string_list[1] is None:
print("please enter something")
else:
self.password = string_list[1]
print("password updated")
else:
print("You don't have permissions to edit this")
# stringList[0] = username, stringList[1] = updated_name
def edit_account_name(self, string_list):
if self.username == string_list[0] or self.accountFlag == 0 or self.accountFlag == 1:
if self.name == string_list[1]:
print("it is the current name")
elif string_list[1] is None:
print("please enter something")
else:
self.name = string_list[1]
print("name updated")
else:
print("You don't have permissions to edit this")
# stringList[0] = username, stringList[1] = updated_address
def edit_account_address(self, string_list):
if self.username == string_list[0] or self.accountFlag == 0 or self.accountFlag == 1:
if self.address == string_list[1]:
print("it is the current address")
elif string_list[1] is None:
print("please enter something")
else:
self.address = string_list[1]
print("address updated")
else:
print("You don't have permissions to edit this")
# stringList[0] = username, stringList[1] = updated_email
def edit_account_email(self, string_list):
if self.username == string_list[0] or self.accountFlag == 0 or self.accountFlag == 1:
if self.email == string_list[1]:
print("it is the current email")
elif string_list[1] is None:
print("please enter something")
else:
self.email = string_list[1]
print("email updated")
else:
print("You don't have permissions to edit this")
# stringList[0] = username, stringList[1] = updated_phone_number
def edit_account_phonenumber(self, string_list):
if self.username == string_list[0] or self.accountFlag == 0 or self.accountFlag == 1:
if self.phonenumber == string_list[1]:
print("it is the current phone number")
elif string_list[1] is None:
print("please enter something")
else:
self.phonenumber = string_list[1]
print("phone number updated")
else:
print("You don't have permissions to edit this")
myDict = {"createaccount": create_account,"deleteaccount": delete_account, "createclass": createClass,
"editaccount": "editaccounts(username)", "printallclass": printAllClasses, "deleteclass": deleteClass,
"addta":assign_TA_class, "addinstructor":assign_instructor_class, "removeinstructor": unassign_instructor_class, "removeta": unassign_TA_class}