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 login(cls, username, password): account = cls.select_one("WHERE password_hash = ? AND username = ?", (hash_pass(password), username)) if not account: return None else: return account
def get_api_key(): username = request.json['username'] password = util.hash_pass(request.json['password']) account = Account.login(username, password) if not account: return jsonify(UNAUTHORIZED), 401 return jsonify({"api_key": account.api_key, "username": account.username})
def add_user(email,password,first_name,last_name): with sqlite3.connect(User.dbpath) as conn: cursor = conn.cursor() SQL = """INSERT INTO users( Email, Password,First_name,Last_name) VALUES (?,?);""" values = (email, hash_pass(password),first_name,last_name) cursor.execute(SQL, values)
def check_user( email, password): with sqlite3.connect(User.dbpath) as conn: cursor = conn.cursor() SQL = """SELECT * FROM users WHERE Email=? AND password=?;""" cursor.execute(SQL, (email,hash_pass(password))) row = cursor.fetchone() if row: return (row[0], row[1], row[2]) return None
def login(): if request.method == 'GET': return render_template('login.html') elif request.method == 'POST': session['username'] = request.form['uname'] session['password'] = util.hash_pass(request.form['pword']) account = Account.login(session['username'], session['password']) if account == None: return render_template('login.html', error=view.invalid_info()) else: session['api_key'] = account.api_key return render_template('dashboard.html', Username=session['username'])
def reset(): account = Account.api_authenticate(session['api_key']) if not account: return redirect(url_for('login')) else: if request.method == 'GET': return render_template('reset.html') else: if request.form['pword'] != request.form['pword_confirm']: return render_template('reset.html', message="Passwords entered do not match. Please re-enter a new password.") else: account.set_password(util.hash_pass(request.form['pword'])) account.save() return render_template('reset.html', message="Password reset successful.")
def __init__(self, **kwargs): for property, value in kwargs.items(): # depending on whether value is an iterable or not, we must # unpack it's value (when **kwargs is request.form, some values # will be a 1-element list) if isinstance(value, list) or isinstance(value, tuple): if len(value) == 1: if not isinstance(value, str) and not isinstance( value, dict): value = value[0] if property == 'password': value = hash_pass(value) # we need bytes here (not plain str) setattr(self, property, value) # initializes automap base class that allows ORM in all tables reflect_prepare(db, self) # initialize a new session for the current model, that expires on commit # TODO: verify performance for bulk-loading/saving db.session = sessionmaker(bind=db.engine, expire_on_commit=True)
def main_menu_ctrl(user): while True: input() os.system("clear") answer = view.main_menu(user.username) if int(answer) == 9: view.program_end() return None elif int(answer) == 8: user.set_password(util.hash_pass(view.set_password_inpt())) user.save() view.saving_change() elif int(answer) == 7: trades = user.get_trades() view.total_trades(len(trades)) for trade in trades: view.trade_detail(trade.volume, trade.ticker, trade.price, trade.price * trade.volume, trade.time) elif int(answer) == 6: positions = user.get_positions() if len(positions) == 0: view.no_positions() else: bal = 0 for position in positions: ticker = position.ticker shares = position.shares px = util.get_price(ticker) bal += px * shares view.stockbal(shares, ticker, px * shares) view.totbal(bal) elif int(answer) == 5: val_ord = True while val_ord == True: ticker = view.ask_ticker() px = float(util.get_price(ticker)) view.show_ticker_price(ticker, px) if user.get_position_for(ticker).shares != 0: shares = view.ask_num_shares() try: y_n = view.confirm_order("sell", ticker, shares, px * shares) if y_n == "y" or "Y": user.sell(ticker, shares) view.total_trades(1) val_ord = False else: view.choose_valid() val_ord = True except ValueError: view.insuf_funds() val_ord = True else: view.no_position_stock() elif int(answer) == 4: val_ord = True while val_ord == True: ticker = view.ask_ticker() px = float(util.get_price(ticker)) view.show_ticker_price(ticker, px) view.bal_and_pos(user.balance) shares = view.ask_num_shares() try: y_n = view.confirm_order("buy", ticker, shares, px * shares) if y_n == "y" or "Y": user.buy(ticker, shares) view.total_trades(1) val_ord = False else: view.choose_valid() val_ord = True except ValueError: view.insuf_funds() val_ord = True elif int(answer) == 3: amt = view.deposit_inpt() user.deposit(amt) view.deposit_outp(amt) view.newbalance_statement(user.balance) elif int(answer) == 2: x = True while x == True: ticker = view.ask_ticker() try: px = util.get_price(ticker) view.show_ticker_price(ticker, px) x = False except requests.ConnectionError: view.choose_valid() elif int(answer) == 1: view.api_key(user.api_key) view.bal_and_pos(user.balance) positions = user.get_positions() if len(positions) == 0: view.no_positions() else: bal = 0 for position in positions: ticker = position.ticker shares = position.shares px = util.get_price(ticker) bal += px * shares view.totbal(bal) view.totport(bal + user.balance) else: view.choose_valid()
def set_password(self, password): self.password_hash = hash_pass(password)