def socket_ping(data): # We pull the user id ourselves to avoid excessive DB queries if request.cookies.get("sid"): s = Session.find(request.cookies.get("sid")) if s: redis.set("user:%s:ping" % s['user'], time.time()) if 'lobby' in data: redis.set("user:%s:lobby:%s:ping" % (s['user'], data['lobby']), time.time())
def beforeRequest(): g.user = None g.uid = -1 g.state = STATE if request.path.startswith("/static"): return # Normal session if request.cookies.get("sid"): s = Session.find(request.cookies.get("sid")) if s: # Eventually we should be lazily loading this in, or cacheing it at redis try: g.user = User.select().where(User.id == s['user']).get() g.uid = g.user.id except User.DoesNotExist: resp = flashy("Wow! Something really went wrong. Contact support!") resp.set_cookie('sid', '', expires=0) return resp