def find_user(cls, session_id): s = cls.one(session_id=session_id) if s is None or s.expired(): return User.guest() else: u = User.one(id=s.user_id) if u is None: return User.guest() else: return u
def current_user(request): if 'session_id' in request.cookies: session_id = request.cookies['session_id'] u = Session.find_user(session_id=session_id) return u else: return User.guest()