Example #1
0
    def wrapper(*args, **kwargs):
        auth = request.headers.get('Authorization')
        if not auth:
            abort(401)
        method, token = auth.split()
        if method != 'bearer' or not token:
            abort(401)

        session = Session.find(token=token)
        if not session:
            abort(401)

        user = User.find(id=session.user_id)
        return func(user=user, session=session, *args, **kwargs)
Example #2
0
    def user_joined(cls, sid, token):
        """
        a new session has been created
        add user's sid to cache with their
        related chat id
        :param sid: socket's sid
        :param token: handshake's token
        """
        session = Session.find(token=token)
        if not session:
            return False

        redis.hset('sid-id', sid, session.user_id)
        redis.hset('id-sid', session.user_id, sid)
        return True