-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (58 loc) · 2.43 KB
/
Copy pathmain.py
File metadata and controls
70 lines (58 loc) · 2.43 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
import sqlite3
import os
from InquirerPy import prompt
import shutil
from pwinput import pwinput
import admin
import student
class tcol:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def print_centre(s):
print(s.center(shutil.get_terminal_size().columns))
def clrscr():
os.system('cls' if os.name=='nt' else 'clear')
def main():
while True:
clrscr()
print_centre(f"{tcol.BOLD}{tcol.UNDERLINE}{tcol.HEADER}Welcome to Database University{tcol.ENDC}")
print_centre(f"{tcol.OKGREEN}Go DB's!{tcol.ENDC}")
try:
choice = prompt({
"type": "list",
"message" : "",
"choices": ["Student Login", "Admin Login", "QUIT"]
})
clrscr()
match choice[0]:
case "Student Login": # User Login
print_centre(f"{tcol.BOLD}{tcol.HEADER}Student Login{tcol.ENDC}")
UID = int(input(f"{tcol.BOLD}{tcol.OKCYAN}Enter UID:\t\t{tcol.ENDC}"))
password = pwinput(f"{tcol.BOLD}{tcol.OKCYAN}Enter Password:\t\t{tcol.ENDC}")
login_success = student.main(UID=UID, password=password)
if (login_success==0):
print_centre(f"{tcol.BOLD}{tcol.FAIL}Login failed. Try again{tcol.ENDC}")
input("Press Enter to continue...")
case "Admin Login": # Admin Login
print_centre(f"{tcol.BOLD}{tcol.HEADER}Admin Login{tcol.ENDC}")
username = input(f"{tcol.BOLD}{tcol.OKCYAN}Enter Email:\t\t{tcol.ENDC}")
password = pwinput(f"{tcol.BOLD}{tcol.OKCYAN}Enter Password:\t\t{tcol.ENDC}")
login_success = admin.main(username, password)
if (login_success==0):
print_centre(f"{tcol.BOLD}{tcol.FAIL}Login failed. Try again{tcol.ENDC}")
input("Press Enter to continue...")
case "QUIT": # Exit
print("Thank you, bye!")
break
case __: # <--- Confirm default case syntax surrounding Exceptions
raise ValueError
except ValueError:
print("Choice not found, please try again.\n")
main()