Ejemplo n.º 1
0
 def test_log_in_success(self):
     with patch("model.sqlite3") as mock_sql:
         mock_sql.connect().cursor().fetchone.return_value = (
             "307e1fb4b8594b49b8eb119a4a38cc5020fd9eb18afa9a38b8c75abb4ac8ae6e",
             "86f712b2c0e419af5f9cfc53f0bd9f0b3cb0c81e4d9299125f2e9e99e504f3a7f"
             "2b534894ffbdca10ce0a5507142c91a4d66f859f6df5771ba04e5fa477f28e0",
         )
         assert m.log_in("asdf", "asdf")
         mock_sql.connect().cursor().fetchone.return_value = ["asdf"]
         assert m.current_user() == "asdf"
Ejemplo n.º 2
0
def login():
	if request.method =='GET':
		return render_template('log_in.html')
	else:
		submitted_username = request.form['username']
		submitted_password = request.form['password']
		if model.log_in(submitted_username,submitted_password):
			session['username'] = submitted_username
			session['password'] = submitted_password
			return redirect('/terminal/mainmenu')
		else:
			return redirect('/terminal/login')
	return ''' 
Ejemplo n.º 3
0
def login():
    cannot_login = None
    m.log_out()
    if request.method == "GET":
        return render_template('login.html')
    else:
        submitted_username = request.form['username']
        submitted_password = request.form['password']
        result = m.log_in(submitted_username, submitted_password)
        if result:
            return redirect('/menu')
        else:
            cannot_login = True
            return render_template('login.html', cannot_login=cannot_login)
Ejemplo n.º 4
0
def login():
    cannot_login = None
    m.log_out()
    if request.method == "GET":
        return render_template("login.html")
    else:
        submitted_username = request.form["username"]
        submitted_password = request.form["password"]
        result = m.log_in(submitted_username, submitted_password)
        if result:
            return redirect("/menu")
        else:
            cannot_login = True
            return render_template("login.html", cannot_login=cannot_login)
Ejemplo n.º 5
0
def login():
    if request.method == "GET":
        return render_template('login.html')
    else:
        submitted_username = request.form['username']
        submitted_password = request.form['password']
        result = m.log_in(submitted_username, submitted_password)
        if result == True:
            username = submitted_username
            #print(username)
            return redirect('/menu')
        else:
            print('please try again')
            return redirect('/login')
Ejemplo n.º 6
0
def login():
    if request.method == 'POST':
        submitted_username = request.form['username']
        submitted_password = request.form['password']
        if model.log_in(submitted_username, submitted_password):
            session['username'] = submitted_username
            session['password'] = submitted_password
            if model.check_admin(submitted_username):
                session['isAdmin'] = True
            else:
                session['isAdmin'] = False
            return redirect('/terminal/mainmenu')
        else:
            return redirect('/terminal/login')
    return ''' 
Ejemplo n.º 7
0
def game_loop():
    current_username = ''
    condition = True
    while 1:
        user_choice = view.log_or_sign()
        user_choice = user_choice.lower()
        log_in = ['l', 'login']
        create_ = ['c', 'create']
        exit_ = ['e', 'exit']
        accept_input = log_in     \
                      +create_     \
                      +exit_
        if user_choice in accept_input:
            if user_choice in log_in:
                (user_name, password) = view.log_menu()
                current_username = user_name
                has_account = model.log_in(user_name, password)
                if has_account:
                    break
                else:
                    print('WRONG LOGIN INFORMATION. TRY AGAIN')
                    import time
                    time.sleep(3)
            elif user_choice in exit_:
                condition = False
                m.log_out()
                os.system('clear')
                break

            elif user_choice in create_:
                #(new_user,new_password,new_funds) = view.create_menu()
                #       new_user = input("username:"******"password:"******"""INSERT INTO user(
                        username,
                        password,
                        current_balance
                    ) VALUES(?,?,?
                    )""", newuser)
                connection.commit()
                cursor.close()
                connection.close()

                print("You have signed up!")
                import time
                time.sleep(3)

    while condition:
        buy_inputs = ['b', 'buy']
        sell_inputs = ['s', 'sell']
        lookup_inputs = ['l', 'lookup']
        quote_inputs = ['q', 'quote']
        exit_inputs = ['e', 'exit']
        acceptable_inputs = buy_inputs     \
                            +sell_inputs   \
                            +lookup_inputs \
                            +quote_inputs  \
                            +exit_inputs
        user_input = view.main_menu()
        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                (ticker_symbol, trade_volume) = view.buy_menu()
                confirmation_message, return_list = model.buy(
                    current_username, ticker_symbol, trade_volume)
                if confirmation_message == True:
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input(
                        "You have enough money. Would you like to buy this stock?\n[y] Yes\n[n] No\n"
                    )
                    if choice in yes:
                        model.buy_db(return_list)
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough money to buy this stock.")
            elif user_input in sell_inputs:
                (ticker_symbol, trade_volume) = view.sell_menu()
                confirmation_message, return_list = model.sell(
                    current_username, ticker_symbol, trade_volume)  #TODO
                if confirmation_message == True:
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input(
                        "You have enough shares to sell. Would you like to sell this stock?\n[y] Yes\n[n] No\n"
                    )
                    if choice.lower() in yes:
                        model.sell_db(return_list)  #TODO
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough shares to sell.")

            elif user_input in lookup_inputs:
                company_name = view.lookup_menu()
                print(model.lookup_ticker_symbol(company_name))
            elif user_input in quote_inputs:
                #TODO
                ticker_symbol = view.quote_menu()
                print(model.quote_last_price(ticker_symbol))
                #import time
                #time.sleep(5)
            elif user_input in exit_inputs:
                os.system('clear')
                break
            else:
                #catches huge error
                #should contain a fallback function
                pass
        else:
            pass
        model.updateHoldings()
        import time
        time.sleep(3)
Ejemplo n.º 8
0
 def test_log_in_failure(self):
     with patch("model.sqlite3") as mock_sql:
         mock_sql.connect().cursor().fetchone.return_value = ("asdf",
                                                              "asdf")
         assert not m.log_in("asdf", "asdf")
Ejemplo n.º 9
0
def game_loop():
    current_username = ''
    condition = True
    while 1:
        user_choice = view.log_or_sign()
        user_choice = user_choice.lower()
        log_in = ['l','login']
        create_ = ['c','create']
        exit_ = ['e','exit']
        accept_input = log_in    \
                    +create_     \
                    +exit_
        if user_choice in accept_input:
            if user_choice in log_in:
                (user_name, password) = view.log_menu()
                current_username = user_name
                has_account = model.log_in(user_name, password)
                if has_account:
                    break
                else:
                    input("You have entered the wrong login information. \nPlease try again. Press enter to continue. ")
            elif user_choice in exit_:
                condition = False
                m.log_out()
                view.clear_screen()
                break
            elif user_choice in create_:
                model.create_()
                print("You have signed up!")
                input("Press enter to continue. ")
    while condition: #while true, the loop continues
        buy_inputs = ['b', 'buy']
        sell_inputs = ['s', 'sell']
        lookup_inputs = ['l', 'lookup']
        quote_inputs = ['q', 'quote']
        funds = ['f', 'funds']
        holdings = ['h', 'holdings']
        transactions = ['t', 'transactions']
        exit_inputs = ['e', 'exit']
        acceptable_inputs = buy_inputs     \
                            +sell_inputs   \
                            +lookup_inputs \
                            +quote_inputs  \
                            +funds         \
                            +holdings      \
                            +transactions  \
                            +exit_inputs
        user_input = view.main_menu()
        user_input = user_input.lower()
        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                (ticker_symbol, trade_volume) = view.buy_menu()
                confirmation_message, return_list = model.buy(current_username, ticker_symbol, trade_volume)
                if confirmation_message == True: #if the transaction cost is less than the current balance
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input("You have enough money. Would you like to buy this stock?\n[y] Yes\n[n] No\n")
                    if choice in yes:
                        model.buy_db(return_list)
                        print("You have bought {} shares of {}. ".format(trade_volume, ticker_symbol))
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough money to buy this stock.")
            elif user_input in sell_inputs:
                (ticker_symbol, trade_volume) = view.sell_menu()
                confirmation_message, return_list = model.sell(current_username, ticker_symbol, trade_volume)
                if confirmation_message == True:
                    yes = ['y', 'yes']
                    no = ['n', 'no']
                    choice = input("You have enough shares to sell. Would you like to sell this stock?\n[y] Yes\n[n] No\n")
                    if choice.lower() in yes:
                        model.sell_db(return_list)
                        print("You have sold {} shares of {}. ".format(trade_volume, ticker_symbol))
                    else:
                        print("Returning to main menu.")
                else:
                    print("You do not have enough shares to sell.")
            elif user_input in lookup_inputs:
                company_name = view.lookup_menu()
                ticker_symbol = model.lookup_ticker_symbol(company_name)
                if len(ticker_symbol) <=6: #if it returns an actual ticker symbol instead of the error message
                    print("The ticker symbol for {} is {}.".format(company_name, ticker_symbol))
                else: #error message
                    print("The ticker symbol for the company you searched cannot be found. \nPlease try again.")
            elif user_input in quote_inputs:
                ticker_symbol = view.quote_menu()
                last_price = model.quote_last_price(ticker_symbol)
                if len(str(last_price)) <= 6:
                    print("The last price for {} is ${}.".format(ticker_symbol, last_price))
                else:
                    print("The last price for the company you searched cannot be found. \nPlease try again.")
            elif user_input in funds:
                view.clear_screen()
                bal = model.funds()
                print("Your current balance is ${}.".format(bal))
            elif user_input in holdings:
                view.clear_screen()
                holdings = m.holdings()
                print("Your current holdings: \n{}".format(holdings))
            elif user_input in transactions:
                view.clear_screen()
                transactions = m.transactions()
                print("All of your previous transactions: \n{}".format(transactions))
            elif user_input in exit_inputs:
                view.clear_screen()
                condition = False
                m.log_out()
                break
            else:
                print("Error.")
        else:
            print("Error.")
        model.update_holdings()
        input("\nPress enter to continue. ")