def login_menu(): while True: try: user_input = view.login_menu() if int(user_input) == 3: view.program_end() sys.exit() elif int(user_input) == 2: username = view.username_inpt() pwd = util.hash_pass(view.password_inpt()) user = Account.login(username, pwd) if user == None: view.invalid_info() return login_menu() return user elif int(user_input) == 1: user = Account() user.username = view.username_inpt() user.set_password(util.hash_pass(view.set_password_inpt())) user.balance = view.deposit_inpt() user.save() view.acc_created(user.username) return user except ValueError: view.choose_valid()
def create_account_selection(): while True: newuser = Account() view.enter_user_name() username = input() newuser.username = username view.enter_password() password = getpass.getpass() newuser.origpassword = password newuser.set_password(password) #newuser.apikey=20 newuser.set_apikey() newuser.balance = 0.00 newuser.save() view.account_success_message() return newuser
def main_loop(): while True: choice = user_menu() if choice is None: # incorrect selection bad_input('Please select option') elif choice == '4': # exit goodbye() break elif choice == '1': login_input = login_username_pw() verified_account = Account.login(login_input) if verified_account: db_password_hash = verified_account[2] password_verify = checkpw(login_input[1].encode(), db_password_hash) if password_verify: account = Account(account_id = verified_account[0]) account.username = verified_account[1] account.balance = int(verified_account[3]) while True: choice = main_menu() if choice is None: bad_input('Please select option') elif choice == '1': # view account balance display_balance(account.balance) elif choice == '2': # deposit funds account.balance += deposit() Account.update_balance(account) elif choice == '3': # buy stock buy_stock = trade_stock() account.buy(buy_stock[0], buy_stock[1]) elif choice == '4': #sell stock buy_stock = trade_stock() account.sell(buy_stock[0], buy_stock[1]) elif choice == '5': # view positions display_positions(Account.get_positions(account)) elif choice == '6': # view trades display_trade_history(Account.get_trades(account)) elif choice == '7': # lookup price of stock ticker = view.lookup_ticker() print("Ticker: {} is currently: ${}".format(ticker, get_price(ticker))) elif choice == '8': # See API Keys display_api(Account.retrieve_api_key(account)) elif choice == '9': # logout goodbye() else: bad_input('Retry') else: bad_input('Incorrect password') else: bad_input('Incorrect username') elif choice == '2': # login with api user_api_key = login_api_key() # print(user_api_key) user = Account.api_authenticate(user_api_key) display_user_from_api_key(user) elif choice == '3': # create new account account_details[0] = "mark" account_details[1] = "1234" account_details[2] = 1000 account_details = create_account() account = Account() account.username = account_details[0] account.password_hash = account_details[1] account.balance = account_details[2] account.api_key = account.generate_api_key() Account.save(account)