-
Notifications
You must be signed in to change notification settings - Fork 0
/
main - Copy.py
211 lines (174 loc) · 8.68 KB
/
main - Copy.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
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
import sys
import logging
from Staff import Staff
from Student import Student
from user import User
from Course import Course
from colorama import Fore, Back, Style
# logging.basicConfig(level= logging.critical('Login has occurred'),filename='info_login.log',filemode='a',datefmt="%d-%b-%y%H:%M:%S")
mylogger = logging.getLogger("loger1")
file_handeler_event = logging.FileHandler('file_event.log')
# file_handeler_error = logging.FileHandler('file_error.log')
std_handeler = logging.StreamHandler()
file_handeler_event.setLevel(logging.INFO)
# file_handeler_error.setLevel(logging.ERROR)
std_handeler.setLevel(logging.ERROR)
log_format = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
file_handeler_event.setFormatter(log_format)
# file_handeler_error.setFormatter(log_format)
mylogger.addHandler(file_handeler_event)
# mylogger.addHandler(file_handeler_error)
mylogger.addHandler(std_handeler)
# Select the login type
print(Fore.MAGENTA + 'select one of these two:\n 1-signin\n 2-signup')
print(Style.RESET_ALL)
user_selection = int(input('your selection: '))
username = input('enter your username: ')
password = input('enter your password: ')
#Build a sample of the class user
username_sample = User(username, password)
# login
if user_selection == 1:
result = username_sample.login()
# Enter the password for three times if it is incorrect
if result == False:
mylogger.error("invalid username or password!")
a = 0
while a < 2:
if result == False:
username = input('enter your username: ')
password = input('enter your password: ')
username_sample = User(username, password)
if result == True:
print(Fore.LIGHTBLUE_EX + '"' + "successfully logged in!" + '"')
print(Style.RESET_ALL)
a = 4
elif result == False and a == 1:
mylogger.error("invalid username or password and you can not log in!")
print(Fore.RED + '"' + "Sorry, you can not log in." + '"')
print(Style.RESET_ALL)
a += 1
else:
mylogger.info("Login done.")
print('\n')
elif user_selection == 2:
username_sample.register()
sys.exit()
else:
print(Fore.RED + '\ninvalid input')
print(Style.RESET_ALL)
# result = username_sample.login()
if result == True:
personal_code = input("Please enter your personal code: ")
"""
The number of characters indicates that the user is a student or staff:
student: 4
staff (Education): 6
staff (Computer site): 7
staff (Financial): 8
"""
""" student """
if len(password) == 4 and username_sample.check_Personal_code(personal_code) == True:
mylogger.info("Personal code and length of your password is correct.")
name, family = input('name,family: ').split(',')
student = Student(name, family)
print(Fore.RED + "1- See course list and selection course \n2- See course and Delete course ")
print(Style.RESET_ALL)
selection = int(input('selection : '))
if selection == 1:
student.read_course()
print(Fore.RED + "Be careful: The number of requested units must be between 10 and 20. ")
print(Style.RESET_ALL)
number_course = int(input('Number of course requested: '))
sum_units_selected = 0
selected_course = []
for i in range(number_course):
course_request = input('Enter course : ')
student.select_course(course_request)
mylogger.info("The course selected.")
fill_capacity = 1
title, professor, id, unit = input("Enter: Title,Professor,ID,Unit : ").split(',')
capacity = int(input('Capacity: '))
sum_units_selected = sum_units_selected + int(unit)
course = Course(title, professor, id, unit, capacity)
course.capacity_update(fill_capacity)
selected_course.append(course_request)
print(Fore.LIGHTGREEN_EX + f'Total requested units:{sum_units_selected} and Elective course is {selected_course}')
print(Style.RESET_ALL)
# print(f'Total requested units:{sum_units_selected} and Elective courses is {course}')
if 10 <= sum_units_selected <= 20:
print(Fore.RED + "The number of requested units is selected successfully. ")
print(Style.RESET_ALL)
else:
print(Fore.RED + "The number of requested units is not between 10 and 20. ")
print(Style.RESET_ALL)
elif selection == 2:
number_course = int(input('Number of course requested to delete: '))
deleted_course = []
for i in range(number_course):
student.read_course()
course_request = input('Enter course to delete : ')
student.delete_course(course_request)
mylogger.info("The course deleted.")
fill_capacity = -1
title, professor, id, unit = input("Enter: Title,Professor,ID,Unit : ").split(',')
capacity = int(input('Capacity: '))
course = Course(title, professor, id, unit, capacity)
course.capacity_update(fill_capacity)
deleted_course.append(course_request)
print(
Fore.LIGHTGREEN_EX + f'Elective course to delete is {course_request}')
print(Style.RESET_ALL)
# else:
# print(Fore.RED + "Personal code or length of your password is incorrect . ")
# print(Style.RESET_ALL)
""" Staff(Education) """
if len(password) == 6 and username_sample.check_Personal_code(personal_code) == True:
name, family = input('name,family: ').split(',')
staff = Staff(name, family)
print(Fore.LIGHTCYAN_EX + "Enter one of the following numbers:"
" \n1- Definition of Course \n2- View and Enroll elective courses ")
print(Style.RESET_ALL)
selection = int(input('selection: '))
if selection == 1:
number_course_define = int(input('How many lessons do you want to define?'))
for i in range(number_course_define):
title, professor, id, unit, capacity = input("Enter: Title,Professor,ID,Unit,Capacity : ").split(',')
course = Course(title,professor,id,unit,capacity)
staff.course_define(title, professor, id, unit, capacity)
elif selection == 2:
name, family = input('Name of student,Family of student: ').split(',')
staff.see_course(name, family)
number_course = int(input('How many lessons do you want to enroll?: '))
for n in range(number_course):
course = input('Course: ')
print('If you approve the choice of course, Enter 1(means True):')
selection = int(input('selection: '))
if selection == 1:
staff.course_enroll(name, family, course, True)
print("Done.")
elif selection == 0:
print(f'The course of {course} was not approved for {name} {family}. ')
"""
Change password by user.
"""
if result == True:
change_pass = int(input("Are you change your password:(Yes:1 , No:2) "))
if change_pass == 1:
password_new = input('Enter new password: ')
if len(password_new) == len(password):
username_sample.change_password(password_new)
# username_sample.login()
elif len(password_new) != len(password):
print(f'Password length must be {len(password)}.')
password_new = input('Enter new password: ')
if len(password_new) == len(password):
username_sample.change_password(password_new)
# username_sample.login()
else:
print('Sorry, you can not log in.')
# Password of Student: 4 character
# Password of Staff(Education) : 6 character
# Password of Staff(Computer Site) : 8 character
# Password of Staff(Financial) : 10 character