-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·157 lines (140 loc) · 6.19 KB
/
main.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
import pymongo
import re
import os
from bson.objectid import ObjectId
import time
client = pymongo.MongoClient("mongodb+srv://faaiz:[email protected]/?retryWrites=true&w=majority")
db = client["Testdb"]
collection = db["users"]
class User:
def create_account(self):
name: str = input("Enter Your name: ")
father_name: str = input("Enter Your fathers' name: ")
age = int(input("Enter your age: "))
password: str = self.pass_check()
amount: int = int(input("Enter initial cash: "))
data = {'Name': name,
'Father name': father_name,
'Age': age,
'Password': password,
'Amount': amount
}
collection.insert_one(data)
return data
@staticmethod
def pass_check():
pattern = re.compile("(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*.])(?=.*[0-9])")
while True:
password = input("Enter Password: ")
ok = re.search(pattern, password)
if len(password) >= 8:
if ok:
return password
else:
print("\nPassword should contain at least:\n1 special character\n1 number!\n1 uppercase letter\n"
"1 lowercase letter\n")
else:
print("\nPassword length less then 8 characters\n")
if __name__=="__main__":
main_switch = True
while main_switch:
os.system("clear")
print("Press 1 to create an account")
print("Press 2 to login to an account")
print("Press 3 to show all users - ADMIN")
print("Press 0 to exit...\n")
inp = input("Choose: ")
if inp == '1':
user = User()
data = user.create_account()
os.system('clear')
for key , value in data.items():
print(key , ":" , value)
input("\nPress Enter key to continue...\n")
os.system('clear')
elif inp == '2':
login_switch = True
id = input("Enter ID: ")
user_id = ObjectId(id)
password = input("Enter Password: ")
user = collection.find_one({"_id": user_id, 'Password': password})
if user:
while login_switch:
os.system("clear")
print("Press 1 to Deposit Money")
print("Press 2 to Withdraw Money")
print("Press 3 to Tansfer Money")
print("Press 4 to show account info.")
print("Press 5 to close account permanently")
print("Press 0 to log out")
inp = input("\nChoose: ")
if inp == '0':
break
elif inp == '1':
cash = int(input("Enter Amount to Deposit: "))
new_amount = cash + user["Amount"]
change = {"$set" : {"Amount": new_amount}}
collection.update_one(user, change)
user = collection.find_one({"_id": user_id})
print("Desposit Successful!!!")
time.sleep(2)
os.system("clear")
elif inp == '2':
cash = int(input("Enter Amount to Withdraw: "))
if user['Amount'] >= cash:
new_amount = user["Amount"] - cash
change = {"$set" : {"Amount": new_amount}}
collection.update_one(user, change)
user = collection.find_one({"_id": user_id})
print("Withdraw Successful!!!")
time.sleep(2)
os.system("clear")
else:
print("Insufficient balance!!!")
time.sleep(2)
elif inp == '3':
print("your Current Balance : {}".format(user["Amount"]))
cash = int(input("Enter amount to transfer: "))
if user['Amount'] >= cash:
rec = input("Enter receiver id: ")
user2 = collection.find_one({"_id": ObjectId(rec)})
if user2:
collection.update_one(user, {"$set" : {"Amount" : user["Amount"] - cash}})
collection.update_one(user2, {"$set" : {"Amount" : user2["Amount"] + cash}})
print("Transfer Successfull")
user = collection.find_one({"_id" : user_id})
print("Your New Balance is : {}".format(user["Amount"]))
time.sleep(3)
else:
print("Receiver Account Not Found!!")
time.sleep(2)
else:
print("Insufficient Balance!!!")
time.sleep(2)
elif inp == '4':
os.system("clear")
for key , value in user.items():
print(key , ":" , value)
input("\nEnter to Continue...\n")
elif inp == '5':
if collection.delete_one(user):
print("Account Closed Successfuly!!\n")
time.sleep(2)
os.system("clear")
break
else:
print("Error Occured!!!")
else:
input("Incorrect Info. Try again...(press Enter to Continue)")
os.system("clear")
elif inp == '3':
all_users = collection.find()
for i in all_users:
print(i)
input("\nPress Enter key to continue...\n")
os.system("clear")
elif inp == '0':
break
else:
print("Wrong input")
time.sleep(2)