Esempio n. 1
0
    def enqueue_song(room_number, url, name, duration, userId):
        url = SecurityUtils.encrypt_url(url)
        room = DBUtils.get_room(room_number)
        queue = room['queue']

        # Assume a song does not exist
        exists = False
        if url in queue:
            exists = True
            queue_list = QueueModerator.sort_pending_songs(queue)
            return False, queue_list

        song = {
            'name': name,
            'score': 0,  # initial score is always 0
            'duration': duration,
            'nickname': DBUtils.get_member(userId,
                                           room_number)[userId]['nickname'],
            'userId': userId
        }

        result = DBUtils.enqueue_song(room['_id'], url, song,
                                      len(queue.keys()) + 1)
        unsorted_queue = DBUtils.get_pending_songs(room_number)
        queue_list = QueueModerator.sort_pending_songs(unsorted_queue)

        return result, queue_list
Esempio n. 2
0
    def checkUser(roomId, cookie, master=False):
        """
        Checks if a given userToken represents an legitimate party room member\n
        It could also check if the userToken belongs to master if "master" flag is present

        :param roomId: room of which the user supposedly belongs to\n
        :param cookie: value saved on the user device in a cookie\n
        :optionalParam master: True - check against master instead of regular user\n
        :returns: if verified - success, else - failure
        """

        #parse the cookie
        userId = token = mac = ''
        parts = cookie.split(':')
        if len(parts) == 3:
            userId = parts[0]
            token = parts[1]
            mac = parts[2]
        else:
            return False

        #check cookie integrity
        if SecurityUtils.generateCookie(userId, token) == cookie:

            #check is cookie not fake
            if master:
                user = DBUtils.get_master(roomId)
                return user is not None and userId in user and token == user[
                    userId]  # check if tokens match
            else:
                user = DBUtils.get_member(userId, roomId)
                return user is not None and userId in user and token == user[
                    userId]['token']

        return False
Esempio n. 3
0
    def block(room_number, userId):
        """
        Block an existing user from entering a party\n
        User is blocked according to IP
        :param room_number:\n
        :param userId:\n
        :return: json{Status}
        """

        #get user
        member = DBUtils.get_member(userId, room_number)

        if member is None:
            return Response.responseFailure(
                "User is not a member of this party room.")
        else:
            member = member[userId]
            #block user IP to block
            result = DBUtils.block_member(userId, member['IP'],
                                          member['nickname'], room_number)

            if result:
                #kick user out
                result = DBUtils.delete_member(userId, room_number)

            if result:
                return Response.responseSuccess(
                    "Kicked user successfully. Blocked user " +
                    member['nickname'] + ".")

        return Response.responseFailure("Failed to block user.")