-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
169 lines (115 loc) · 4.13 KB
/
auth.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
158
159
160
161
162
163
164
165
166
167
168
169
import random
import validation
import database
from getpass import getpass
# initialization function
def init():
isValidOptionsSelected = False
print('Welcome to Bank Ruby')
haveAccount = int(input('Do you have an account with us: (1) Yes (2) No (3) Exit \n'))
if(haveAccount == 1):
login()
elif(haveAccount == 2):
register()
elif(haveAccount == 3):
print('Thank you for banking with us')
exit()
else:
print('You have selected invalid option')
init()
# login function
def login():
print('********** Login **********')
accountNumberFromUser = input('Enter your account number: \n')
isValidAccountNumber = validation.accountNumberValidation(accountNumberFromUser)
if isValidAccountNumber:
password = input('Enter password: ')
# password = getpass('Enter password: ')
user = database.authenticateUser(accountNumberFromUser, password)
if user:
bankOperation(user)
# for accountNumber, userDetails in database.items():
# if accountNumber == int(accountNumberFromUser):
# if userDetails[3] == password:
# bankOperation(userDetails)
print('Invalid account or password')
login()
else:
print('Account Number invalid: check that you have up to 10 digits and only integers')
init()
# register function
def register():
print('******* Register ********')
email = input('Email address: ')
firstName = input('First Name: ')
lastName = input('Last Name: ')
password = input('Create password: ')
# password: str = getpass('Create password: ')
accountNumber = generateAccountNumber()
# using database module to create new user record
isUserCreated = database.create(
accountNumber, firstName, lastName, email, password)
if isUserCreated:
print('Your account has been created')
print('== ==== ====== ==== ===')
print('Your account number is : %d' %accountNumber)
print('Make sure you keep it safe')
print('== ==== ====== ==== ===')
login()
else:
print('Something went wrong, please try again')
register()
# bank operation
def bankOperation(user):
print('Welcome %s %s' % (user[0], user[1]))
selectedOption = int(input('What would you like to do today: (1) Deposit (2) Withdrawal (3) Logout (4) Exit \n'))
if selectedOption == 1:
depositOperation()
elif selectedOption == 2:
withdrawalOperation()
elif selectedOption == 3:
logout()
elif selectedOption == 4:
exit()
else:
print('Invalid option selected')
bankOperation(user)
def withdrawalOperation():
print('Withdrawal')
# get current balance
# getCurrentBalance(userDetails, balance)
# get amount to withdraw
# check if current balance > withdraw balance
# deduct withdrawn amount form current balance
# display current balance
def depositOperation():
print('Deposit Operations')
# get current balance
# get amount to deposit
# add deposited amount to current balance
# display current balance
userSelection = int(input('Do you want to perform another operation: (1) Yes (2) No \n'))
if userSelection == 1:
bankOperation()
elif userSelection == 2:
logout()
else:
print('You have selected a wrong option')
# generate account number
def generateAccountNumber():
# Generating Account Number
return random.randrange(0000000000, 9999999999)
def getCurrentBalance(userDetails, balance):
return userDetails[4] == balance
def logout():
# clear all session
print('Thank you for banking with us')
userSelection = int(input('*** Will you to login again: (1) Yes (2) No ***\n'))
if userSelection == 1:
login()
elif userSelection == 2:
exit()
else:
print('You have selected a wrong option')
# Actual Banking System
init()