-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManagement.py
More file actions
94 lines (86 loc) · 3.75 KB
/
Copy pathUserManagement.py
File metadata and controls
94 lines (86 loc) · 3.75 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from DBHelper import DBHelper
import ChyperMap
import utilities
class UserManagement:
def Login(self):
print("Enter your credentials to login:\n")
userEmail = input("Enter your Email:\n")
userPassword = input("Enter your Password:\n").upper()
encryptedPassword = userPassword.translate(ChyperMap.character_map)
userChecked = self.checkIfUserExist(userEmail)
if userChecked[0]:
# fetch second position form tuple, then first object of array and in last first position of tuple
if userChecked[1][0][0] == encryptedPassword:
DBHelper().updateUser(userEmail)
self.takeBackup()
print("------------------------")
print("{} Successfully Login.".format(userEmail))
print("------------------------")
updatedUser = self.getUpdatedUserByEmail(userEmail)
utilities.show_UserAccessCount(userEmail, updatedUser[1][0][1])
self.Continue()
else:
print("Please enter valid password.\n")
self.Login()
else:
print("{} email-id not found in database.".format(userEmail))
self.get_Menu()
def RegisterUser(self):
print("User Registration")
userEmail = input("Enter Email:\n")
userPassword = input("Enter Password:\n").upper()
if self.checkIfUserExist(userEmail)[0]:
print("{} found in database, you can't use it.".format(userEmail))
self.get_Menu()
else:
encryptedPassword = userPassword.translate(ChyperMap.character_map)
DBHelper().insertUser(userEmail, encryptedPassword)
#DBHelper().updateUser(userEmail)
self.takeBackup()
print("--------------------------------------------")
print("Congratulation!!, User Successfully Created.")
print("--------------------------------------------")
self.Continue()
def checkIfUserExist(self, userEmail):
dbResults = DBHelper().selectUser(userEmail)
if len(dbResults) == 0:
return False, []
else:
return True, dbResults
def getUpdatedUserByEmail(self,email):
result = self.checkIfUserExist(email)
return result[0], result[1]
def Continue(self):
inputCorrect = False
while not inputCorrect:
print("########################################################")
user_input = input("Do you wants to Continue? Press 'Y' for YES and 'N' for NO:\n").upper()
if user_input == 'N':
inputCorrect = True
print("Thank you for visiting.")
elif user_input == 'Y':
inputCorrect = True
self.get_Menu()
else:
print("Please enter valid input.\n")
def get_Menu(self):
print("1. Create User")
print("2. Login")
print("3. Quit")
correct_input = False
while not correct_input:
selectedOption = input("Please enter valid choice from above options:\n")
enteredValue = utilities.int_Validator(selectedOption)
if enteredValue[0] and enteredValue[1] < 4:
correct_input = True
if enteredValue[1] == 1:
self.RegisterUser()
elif enteredValue[1] == 2:
self.Login()
elif enteredValue[1] == 3:
print("Thank you for visiting.")
else:
pass
def takeBackup(self):
results = DBHelper().selectAllUsers()
utilities.writeBackup(results)