diff --git a/__pycache__/database.cpython-38.pyc b/__pycache__/database.cpython-38.pyc new file mode 100644 index 0000000..27cc417 Binary files /dev/null and b/__pycache__/database.cpython-38.pyc differ diff --git a/__pycache__/validation.cpython-38.pyc b/__pycache__/validation.cpython-38.pyc new file mode 100644 index 0000000..44ed544 Binary files /dev/null and b/__pycache__/validation.cpython-38.pyc differ diff --git a/auth.py b/auth.py index dc7629f..9bda8f4 100644 --- a/auth.py +++ b/auth.py @@ -15,6 +15,7 @@ import database from getpass import getpass +account_number_from_user = None def init(): print("Welcome to bankPHP") @@ -37,6 +38,7 @@ def 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) @@ -92,7 +94,7 @@ def bank_operation(user): if selected_option == 1: - deposit_operation() + deposit_operation(user) elif selected_option == 2: withdrawal_operation() @@ -117,8 +119,21 @@ def withdrawal_operation(): # display current balance -def deposit_operation(): - print("Deposit Operations") +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 diff --git a/data/user_record/6277302096.txt b/data/user_record/6277302096.txt new file mode 100644 index 0000000..dfb9cfe --- /dev/null +++ b/data/user_record/6277302096.txt @@ -0,0 +1 @@ +Test,User,test@user.com,testuser,550 \ No newline at end of file diff --git a/database.py b/database.py index 0a40169..b4ab516 100644 --- a/database.py +++ b/database.py @@ -10,6 +10,7 @@ import validation user_db_path = "data/user_record/" +auth_session_path = "data/auth_session" def create(user_account_number, first_name, last_name, email, password): @@ -44,12 +45,12 @@ def create(user_account_number, first_name, last_name, email, password): else: - f.write(str(user_data)); + f.write(str(user_data)) completion_state = True finally: - f.close(); + f.close() return completion_state @@ -85,14 +86,16 @@ def read(user_account_number): return False -def update(user_account_number): - print("update user record") - # find user with account number - # fetch the content of the file - # update the content of the file - # save the file - # return true +def update(user_account_number, user_details): + user = user_details[0] + "," + user_details[1] + "," + user_details[2] + "," + user_details[3] + "," + user_details[4] + + try: + f = open(user_db_path + str(user_account_number) + ".txt", "w") + f.write(user) + return True + except: + return False def delete(user_account_number):