def login(): if 'token' in session: return "Already logged in!" req = request.get_json() email = req['email'] password = req['password'] try: token = log_in(email, password)['access_token'] payload = verify_decode_jwt(token) id = payload["sub"][6:] trader = Trader.query.get(id) if not trader: trader = Trader(id=id, name="Test Account", email=email, cash=10000) trader.insert() session['token'] = token stocks = Possession.query.filter(Possession.trader_id == id) except: abort(403) message = f''' Hello {trader.name}! You have {trader.cash} dollars in your account. ''' for stock in stocks: message = message + f"You have {stock.position} shares of {stock.stock_code}.\n" db.session.close() return message
def traderIndex(request, userid): template = loader.get_template('trader/index.html') if Trader.objects.filter(fbuserid=userid).count() < 1: t = Trader(fbuserid=userid) t.save() trader = Trader.objects.get(fbuserid=userid) sr = request.POST['signed_request'] rq = RequestContext(request, {'magicstring':sr}) return HttpResponse(template.render(rq))
def get_trader(user): if user.is_authenticated() and user.is_active: trader = user.traders.all() if trader: trader = trader[0] else: f, c = FundHolder.objects.get_or_create(code='NA') trader = Trader(fund_holder=f, user=user) trader.save() else: raise PermissionDenied('User not authenticated or not active') return trader
def get_trader(user): if user.is_authenticated() and user.is_active: trader = user.traders.all() if trader: trader = trader[0] else: f,c = FundHolder.objects.get_or_create(code = 'NA') trader = Trader(fund_holder = f, user = user) trader.save() else: raise PermissionDenied('User not authenticated or not active') return trader
def register(): req = request.get_json() name = req['name'] email = req['email'] password = req['password'] id = sign_up(email, password)['_id'] try: trader = Trader(id=id, name=name, email=email, cash=10000) trader.insert() db.session.close() except: abort(422) return jsonify({"success": True})