def deposit(user): "Deposit money to current users acc." db = get_DB() cursor = get_Cursor() money = int(input("Amount to be deposited:")) acc = user.accno # acc is the account no. of the current user balance = int(user.balance[0]) balance += money # in users table query = "update users set balance = %s where accno=%s" % (balance, acc) cursor.execute(query) # in transaction table cursor.execute( "insert into transactionhistory(user2accno, amount) values(%s,%s)", (acc, money)) db.commit() # new balance object cursor.execute("select balance from users where accno = %s", (acc, )) balance = cursor.fetchone() user.balance = balance print("Deposited Rs.", money, "in account-", acc)
def transfer(user): "Transfer money to other users" print() balance = user.balance[0] if balance == 0: # check for balance print("You can't transfer money.") print("Balance: 0") else: db = get_DB() cursor = get_Cursor() acc = user.accno acc2 = int(input("Account number of the recipient:")) cursor.execute("select * from users") # cursor = get_Cursor() data = cursor.fetchall() a = False for row in data: if row[2] == acc2 and acc2 != acc: a = True money = int(input("Amount to be trasfered:")) if money > balance: print() print("Amount exceeds current balance.") print("Can't transfer.") print() else: # in users table query = "update users set balance = balance - %s where accno=%s" % ( money, acc, ) cursor.execute(query) query2 = ( "update users set balance = balance + %s where accno=%s" % ( money, acc2, )) cursor.execute(query2) db.commit # in transaction table cursor.execute( "insert into transactionhistory(user1accno, user2accno, amount) values(%s,%s,%s)", (acc, acc2, money), ) db.commit() # new balance object cursor.execute( "select balance from users where accno = %s", (acc, )) balance = cursor.fetchone() user.balance = balance print("Transfered Rs.", money, "to account no.-", acc2) print() if a == False: print("Account no.", acc2, "doesn't exist.") print()
def withdraw(user): "Withdraw money from current users acc." print() balance = user.balance[0] if balance == 0: # check for balance print() print("You can't withdraw money.") print("Balance: 0") print() else: money = int(input("Amount to be withdrawn:")) if money > balance: print() print("Amount exceeds current balance.") print("Can't withdraw.") print() else: balance -= money db = get_DB() cursor = get_Cursor() acc = user.accno # acc is the account no. of the current user # in users table query = "update users set balance = %s where accno=%s" % (balance, acc) cursor.execute(query) # in transaction table cursor.execute( "insert into transactionhistory(user1accno, amount) values(%s,%s)", (acc, money), ) db.commit() # new balance object cursor.execute("select balance from users where accno = %s", (acc, )) balance = cursor.fetchone() user.balance = balance print("Withdrew Rs.", money, "from account-", acc) print()
def usercreation(): """ Gets name, password(twice), and updates db. user gets auto-generated accno. """ import getpass cursor = get_Cursor() db = get_DB() fname = input("Your firstname:") lname = input("Your lastname:") flag = True while flag: # taking password twice and cnfirming password for i in range(0, 2): if i == 0: passwd = getpass.getpass("Enter a password:"******"Confirm password:"******"Password confirmed.") flag = False else: print("Passwords do not match.") print("Try again.") flag = True cursor.execute( "insert into users(firstname,lastname,passwd) values(%s,%s,%s)", (fname, lname, passwd), ) # cursor=get_Cursor() db.commit() print("Created new account.") cursor.execute("select max(accno) from users;") acc = cursor.fetchone() print("Your account number is-", acc[0]) print("Type 'details' to check your account details.")
def updateinfo(user): print() db = get_DB() acc = user.accno cursor = get_Cursor() flag = True while flag == True: print("firstname | lastname | password") print() q = input("What would you like to change from above?") if q == "firstname": fname = input("Your firstname:") query = "update users set firstname = %s where accno=%s" val = (fname, acc) cursor.execute(query, val) db.commit() print("firstname would be updated after you signout") elif q == "lastname": lname = input("Your lastname:") query = "update users set lastname = %s where accno=%s" val = (lname, acc) cursor.execute(query, val) db.commit() print("lastname would be updated after you signout.") elif q == "password": query = "select * from users where accno=%s" % (acc) cursor.execute(query) data = cursor.fetchall() cur_pass = getpass.getpass("Enter your current password:"******"Enter new password:"******"Confirm new password:"******"Password confirmed.") flag = False else: print("Passwords do not match.") print("Try again.") print() flag = True break else: print("Password incorrect.") if flag == False: query = "update users set passwd = %s where accno=%s" % ( passwd2, acc, ) cursor.execute(query) db.commit() print("Password updated") else: print("You didnt choose the correct option") print() question = input("Would you like to change anything else?(yes/no)") if question == "no": flag = False elif question == "yes": flag == True print()
def delete(user): db = get_DB() acc = user.accno cursor = get_Cursor() query = "select * from users where accno=%s" % (acc) cursor.execute(query) data = cursor.fetchall() print() print("you're account will be permanently closed") confirm = input("Are you sure you want to continue?(yes/no)") if confirm == "yes": flag = False while flag == False: # user authentication print() acc = int(input("Enter your account no.:")) if acc == 0: break passwd = getpass.getpass("Enter your password:"******"Account no. and password confirmed.") flag = True break if flag == False: print() print("Account no. or the password is wrong. Try again.") print("Press 0 to cancel") if flag == True: print() confirm2 = input( "The account will now be closed. Press 'enter' to continue or 'c' to cancel." ) if confirm2 == "c": print("Canceled account deletion.") else: money = user.balance[0] if money != 0: print() acc2 = int( input( "To which account no. would you like to transfer your money" ) ) cursor.execute("select * from users") # cursor = get_Cursor() data = cursor.fetchall() a = False for row in data: if row[2] == acc2 and acc2 != acc: a = True # in users table query = ( "update users set balance = balance - %s where accno=%s" % ( money, acc, ) ) cursor.execute(query) query2 = ( "update users set balance = balance + %s where accno=%s" % ( money, acc2, ) ) cursor.execute(query2) db.commit # in transaction table cursor.execute( "insert into transactionhistory(user1accno, user2accno, amount) values(%s,%s,%s)", (acc, acc2, money), ) db.commit() print("Transfered Rs.", money, "to account no.-", acc2) break if a == False: print("Account no.", acc2, "doesn't exist.") else: print("Balance: 0") val = ("administrator123", acc) query = "update users set passwd = %s where accno=%s" cursor.execute(query, val) db.commit() print() print("Account has been closed.") print("You are signed out.") print() return None