-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathauth.py
159 lines (100 loc) · 3.57 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
# register
# - first name, last name, password, email
# - generate user account number
# login
# - account number & password
# bank operations
# Initializing the system
import random
import validation
import database
from getpass import getpass
account_number_from_user = None
def init():
print("Welcome to bankPHP")
have_account = int(input("Do you have account with us: 1 (yes) 2 (no) \n"))
if have_account == 1:
login()
elif have_account == 2:
register()
else:
print("You have selected invalid option")
init()
def login():
print("********* Login ***********")
global account_number_from_user
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')
login()
else:
print("Account Number Invalid: check that you have up to 10 digits and only integers")
init()
def register():
print("****** Register *******")
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) withdrawal (3) Logout (4) Exit \n"))
if selected_option == 1:
deposit_operation(user)
elif selected_option == 2:
withdrawal_operation()
elif selected_option == 3:
logout()
elif selected_option == 4:
exit()
else:
print("Invalid option selected")
bank_operation(user)
def withdrawal_operation():
print("withdrawal")
# get current balance
# get amount to withdraw
# check if current balance > withdraw balance
# deduct withdrawn amount form current balance
# display current balance
def deposit_operation(user):
current_balance = int(get_current_balance(user))
amount_to_deposit = int(input("How much do you want to deposit? "))
current_balance += amount_to_deposit
set_current_balance(user, str(current_balance))
if database.update(account_number_from_user, user):
print("Your account balance is {}".format(current_balance))
bank_operation(user)
else:
print("Transaction not successful")
bank_operation(user)
# get current balance
# get amount to deposit
# add deposited amount to current balance
# display current balance
def generation_account_number():
return random.randrange(1111111111, 9999999999)
def set_current_balance(user_details, balance):
user_details[4] = balance
def get_current_balance(user_details):
return user_details[4]
def logout():
login()
init()