-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
127 lines (111 loc) · 4.18 KB
/
user.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
import json
from os import system
logo = """
_____ _ ___ ___ _
| ___| | | | \/ | | |
| |__ _ __ ___ _ __ | | ___ _ _ ___ ___ | . . | __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_
| __| '_ ` _ \| '_ \| |/ _ \| | | |/ _ \/ _ \ | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '_ ` _ \ / _ \ '_ \| __|
| |__| | | | | | |_) | | (_) | |_| | __/ __/ | | | | (_| | | | | (_| | (_| | __/ | | | | | __/ | | | |_
\____/_| |_| |_| .__/|_|\___/ \__, |\___|\___| \_| |_/\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__|
| | __/ | __/ |
|_| |___/ |___/
"""
system('cls')
system('color 0A')
def login_menu():
system('cls')
print(logo)
print()
print(' ╔════════════╗')
print(' ║ (1) Login ║')
print(' ║ (2) Signin ║')
print(' ╚════════════╝')
print()
choice = input("Enter your choice: ")
if choice == '1':
login()
if choice == '2':
signin()
else:
login_menu()
def login():
system('cls')
print(logo)
print()
print("Welcome Employee")
print("Please Login:")
print("")
print("ID:")
user_id = input(" > ")
print("Password:")
user_password = input(" > ")
if authenticate_user(user_id, user_password) == True:
menu()
else:
login()
def signin():
system('cls')
print(logo)
print()
print(' ╔═════════╗')
print(' ║ Sign in ║')
print(' ╚═════════╝')
print()
print('To create account, please contact the system administrator.')
print()
input('Press Enter key to continue.')
menu()
def authenticate_user(user_id, user_password):
with open('employees.json', 'r') as file:
for line in file:
user_data = json.loads(line)
if int(user_id) == user_data.get('ID') and (user_password) == user_data.get('Password'):
user_name = user_data.get('First Name') + ' ' + user_data.get('Last Name')
global ID
global Name
ID = user_id
Name = user_name
return True
return False
def menu():
system('cls')
print(logo)
print()
print("Logged in as " + Name + ".")
print()
print(' ╔══════════════════╗')
print(' ║ (1) View Profile ║')
print(' ╠══════════════════╣')
print(' ║ (2) Logout ║')
print(' ╚══════════════════╝')
print()
choice = input("Enter your choice: ")
if choice == '1':
view_profile()
elif choice == '2':
print("Logged out successfully.")
login()
else:
print("Invalid choice. Please try again.")
menu()
def view_profile():
system('cls')
print(' ╔═══════════════╗')
print(' ║ Show Profile: ║')
print(' ╚═══════════════╝')
print()
with open('employees.json', mode='r') as file:
for line in file:
employee = json.loads(line)
if employee['ID'] == int(ID):
print('Employee Found:')
print('Employee ID:', employee['ID'])
print('Employee First Name:', employee['First Name'])
print('Employee Last Name:', employee['Last Name'])
print('Employee Age:', employee['Age'])
print('Employee Gender:', employee['Gender'])
print('Employee Role:', employee['Role'])
print('')
input('Press Enter key to continue.')
menu()
login()