-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.py
65 lines (56 loc) · 1.98 KB
/
login.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
"""Implementation of the login class."""
from iam.handler.admin import Admin
from iam.handler.employee import Employee
from iam.utils.models import User
from iam.utils.models import db_url
from sqlalchemy import create_engine
from iam.handler.crypt import encrypt_message, decrypt_message
from sqlalchemy.orm import sessionmaker
from iam.handler.utilities import Register
from iam.utils.Enums import Input
engine = create_engine(db_url)
Session = sessionmaker(bind=engine)
session = Session()
class main:
def choice_input(self, db):
"""
Function to take user input.
"""
choice = input(">>> ").lstrip()
return choice
def Login(self, db):
"""
Login functionality and employee validation.
"""
print('Welcome to Cab booking Login')
uname = input(Input.username.value)
passwd = input(Input.password.value)
result = session.query(User).filter_by(username=uname)
if result.first() is None:
print(Input.no_users.value)
print(Input.login_again.value)
exit()
for row in result:
if decrypt_message(row.password.encode()) == passwd:
if row.type == 'employee':
print(Input.welcome_employee.value)
Employee(row.emp_id).selection()
elif row.type == 'admin':
print(Input.welcome_admin.value)
Admin().selection()
else:
print('incorrect password')
def Login_master(self, db):
"""
Implementation of the menu.
"""
while True:
print(Input.menu.value)
choice = main().choice_input(db)
switcher = {
'1': 'main().Login(db)',
'2': 'Register().newUser("employee")',
'3': 'Register().newUser("admin")',
'4': 'exit()'
}
eval(switcher.get(choice, "print('Invalid choice')"))