예제 #1
0
def contact():
    if session.get('logged_in'):
        with sqlite3.connect('mainDB.db') as conn:
            cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
            cash = '${:20,.2f}'.format(cash)
        return render_template("contact.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), UserCash=cash)
    else:
        return render_template("contact.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())
예제 #2
0
def home(name=WEB_APP_NAME, lb_data=getDashboardData()):
    if not session.get('logged_in'):
        return render_template('login.html', ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())
    else:
        with sqlite3.connect('mainDB.db') as conn:
            cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
            cash = '${:20,.2f}'.format(cash)
            netvalue = DBTools.getNetWorth(conn=conn, userID=str(session['UserName']).lower())
            netvalue = '${:20,.2f}'.format(netvalue)
        return render_template("dashboard.html", data=lb_data, ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), UserCash=cash, NetValue=netvalue)
예제 #3
0
def leaderboard():
    with sqlite3.connect('mainDB.db') as conn:
        data = DBTools.getUserRanks(conn)
        length = len(data) + 1
        data = json.dumps(data)
    if session.get('logged_in'):
        cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
        cash = '${:20,.2f}'.format(cash)
        return render_template("leaderboard.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), data=data, length=length, UserCash=cash)
    else:
        return render_template("leaderboard.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), data=data, length=length)
예제 #4
0
def signup():
    NewName1 = request.form['firstname']
    NewName2 = request.form['lastname']
    NewUser = request.form['newUser']
    NewEmail = request.form['useremail']
    NewPass = request.form['PASSword2']
    conn = sqlite3.connect('mainDB.db')
    DBTools.addUser(conn, NewUser, NewEmail, NewPass, NewName1, NewName2, cash=10000.00, usertype='Standard', groupID=None)

    if not session.get('logged_in'):
        return render_template('login.html', ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())

    return render_template("signup.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())
예제 #5
0
def portfolio():
    if session.get('logged_in'):
        with sqlite3.connect('mainDB.db') as conn:
            userID = session['UserName']
            userID = str(userID).lower()
            data = DBTools.getOwnedStocksByID(conn, userID)
            length = len(data) + 1
            data = json.dumps(data)
            cash = DBTools.getUserCash(conn, userID=str(userID))
            cash = '${:20,.2f}'.format(cash)
            data2 = DBTools.getOwnedStocksByIDPrices(conn, userID=userID)
            length2 = len(data2) + 1
            data2 = json.dumps(data2)
            portfolioValue = DBTools.getPortfolioValue(conn, DBTools.getAllPortData(conn, userID=userID)[0]['portfolioID'])
            portfolioValue = '${:20,.2f}'.format(portfolioValue)

        return render_template("portfolio.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks(), data=data, length=length, UserCash=cash, length2=length2, prices=data2, portValue=portfolioValue)
    else:
        return render_template("login.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())
예제 #6
0
def stock_profile(ticker):

    tickerpath = ticker + ".html"
    grabStockGraph(ticker)
    # Action = request.form['Action']
    # Quantity = request.form['Quantity']
    data = StockPrices.getAllStockData(ticker)
    # print(data)

    sUrl = url_for('static', filename='./stockplots/' + tickerpath)


    if session.get('logged_in'):
        with sqlite3.connect('mainDB.db') as conn:
            Quant = DBTools.getPortfolioStocks(conn, str(session['UserName']).lower(), ticker)
            cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
            cash = '${:20,.2f}'.format(cash)
        return render_template("stock.html", ad=ad_factory.get_ad(1), availableStocks=DBTools.getAvailableStocks(), ticker=ticker, sUrl=sUrl, stock_data=data, ownedQuantity=Quant, UserCash=cash)
    else:
        return render_template("login.html", ad=ad_factory.get_ad(1), availableStocks=DBTools.getAvailableStocks())
예제 #7
0
def do_admin_login():
    if request.form['signup'] == "login":
        conn = sqlite3.connect('mainDB.db')
        #conn = sqlite3.connect('mainDB.db')
        User = request.form['username']
        Pass = request.form['password']
        #file = open('testfile.txt','w')
        if not User:
            User = "******"
        User = User.lower()
        cur = conn.cursor()

        cur.execute("SELECT * from User where userID = ?;",(User,))
        rows = cur.fetchall();
        if(len(rows) > 0):
            #file.write(str(User))
            cur.execute("SELECT salt,password from User where userID = ?;",(User,))
            rows = cur.fetchall();
            Salt = rows[0][0]
            Password = rows[0][1]

            BSalt = Salt.encode('UTF-8')
            BPassword = Pass.encode('UTF-8')
            dk = hashlib.pbkdf2_hmac('sha256',BPassword,BSalt,100000)
            g = binascii.hexlify(dk).decode()
            #file.write(str(Salt))
            #file.write(str(Password))
            if(g == Password):
                session['logged_in'] = True
                session['UserName'] = User
            else:
                print("BadLogin")

            conn.close()

    elif request.form['signup'] == "SignUp":
        return render_template("signup.html", ad=ad_factory.get_ad(), availableStocks=DBTools.getAvailableStocks())

    return home()
예제 #8
0
def PostStock():
    with sqlite3.connect('mainDB.db') as conn:
        Action = request.form['Action']
        Quantity = request.form['Quantity']
        Ticker = request.form['Ticker']

        TickerPath = Ticker + ".html"
        data = StockPrices.getAllStockData(Ticker)
        sUrl = url_for('static', filename='./stockplots/' + TickerPath)
        User = session['UserName']

        # file = open('testfile.txt','w')
        # file.write(str(User))
        # file.close()
        User2 = str(User)
        Price = StockPrices.getPrice(Ticker)
        Price = float(Price)
        Quantity = float(Quantity)
        total = (Price * Quantity)
        total = '${:20,.2f}'.format(total)
        port = DBTools.getAllPortData(conn, User2)[0]['portfolioID']

        if(Action == 'Buy'):
            if(Trades.buyStock(conn, Ticker, port, Price, Quantity)):
                flash("Purchased " + str(Quantity) + " Stock from " + str(Ticker) + " for " + str(total))
            else:
                flash("Could not Complete Purchase")
        elif(Action == 'Sell'):
            if(Trades.sellStock(conn, Ticker, port, Price, Quantity)):
                flash("Sold " + str(Quantity) + " Stock from " + str(Ticker) + " for " + str(total))
            else:
                flash("Could not Sell Stock")
        Quant = DBTools.getPortfolioStocks(conn, str(session['UserName']).lower(), Ticker)
        cash = DBTools.getUserCash(conn, userID=str(session['UserName']).lower())
        cash = '${:20,.2f}'.format(cash)
        return render_template("stock.html", ad=ad_factory.get_ad(1), availableStocks=DBTools.getAvailableStocks(), ticker=Ticker, sUrl=sUrl, stock_data=data, ownedQuantity=Quant, UserCash=cash)