-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
152 lines (113 loc) · 4.42 KB
/
auth.py
File metadata and controls
152 lines (113 loc) · 4.42 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
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
import random # generate account number for new user
import time # show time to user upon login
import validation
import database
from getpass import getpass
localtime = time.asctime(time.localtime(time.time()))
print("Current local time is :", localtime)
# register
# - first name, last name , email
# - generate user account
# login
# - account number and and password
def init():
#isValidOptionSelected = False
print("Welcome of Bank of QueenB!")
#while isValidOptionSelected == False:
haveAccount = int(input("Do you have an account with us: 1 (yes) or 2 (no)? \n"))
if (haveAccount == 1):
isValidOptionSelected = True
login()
elif (haveAccount == 2):
isValidOptionSelected = True
register()
else:
print("You have entered an invalid selection!")
def login():
print("Please login to your account.")
account_number_from_user = input("What is your account number? \n")
is_valid_account_number = validation.account_number_validation(account_number_from_user)
if is_valid_account_number:
password = getpass("What is your password \n")
user = database.authenticated_user(account_number_from_user, password)
if user:
bank_operation(user)
print("Invalid account or password, please try again!") # didnt check for validation
login()
else:
print("Account number is invalid: check that you have up to 10 digits and only integers")
init()
def register():
print("******** Register now! ********* ")
email = input("What is your email address? \n")
first_name = input("What is your first name? \n")
last_name = input("What is your last name? \n")
password = getpass("Create a password for yourself \n")
account_number = generation_account_number()
is_user_created = database.create(account_number, first_name, last_name, email, password)
if is_user_created:
print("Your Account Has been created")
print(" == ==== ====== ===== ===")
print("Your account number is: %d" % account_number)
print("Make sure you keep it safe")
print(" == ==== ====== ===== ===")
login()
else:
print("Something went wrong, please try again")
register()
def bank_operation(user):
print("Welcome %s %s " % (user[0], user[1]))
selected_option = int(input("What would you like to do? (1) deposit (2) withdrawl (3) Logout (4) Report Issue (5) Exit).\n"))
if (selected_option == 1):
deposit_operation(user)
elif (selected_option == 2):
withdrawal_operation(user)
elif (selected_option == 3):
login()
elif (selected_option == 4):#Added new selection for user from previous assignment
report_complaint()
elif (selected_option == 5):
exit() # to leave the program
else:
print("Invalid Option selected, please try again!")
bank_operation(user)
##set up new functions from each operation: withdrawl, deposit and complaint
def withdrawal_operation(user):
withdrawal_amount = int(input("How much would you like to withdraw? \n"))
print("You withdrew $%s" % withdrawal_amount + "!\n")
balance = int((user[4]))
new_balance = str(balance - int(withdrawal_amount))
print("Your current balance is $ %s!" % new_balance)
database.withdrawal(user, withdrawal_amount)
init()
pass
#Improvement
def deposit_operation(user):
deposit_amount = int(input("How much would you like to deposit? \n"))
print("You have deposited $ %s"% deposit_amount + "! \n")
current_balance = int((user[4]))
updated_balance = str(current_balance + int(deposit_amount))
print("Your current balance is now $ %s" % updated_balance)
database.deposit(user, deposit_amount)
init()
pass
def generation_account_number():
# print("Generating Account Number") ## dont need to show this to user
return random.randrange(1111111111, 9999999999)
#Improvement
def report_complaint():
# print("You selected option %s" % selectedOption)
complaint = input("What issue will you like to report? \n")
print("Thank you for contacting us! \n")
pass
#4/16 Improvement
def set_current_balance(user_details, balance):
user_details[4] = balance
#4/16 Improvement
def get_current_balance(user_details):
return user_details[4] # 4 is the position of balance
def logout():
login()
###Actual Banking System ###
### print(generateAccountNumber())
init()