Exemplo n.º 1
0
def authCommSession(req, res, session):
    if req.user or req.uchan:
        if req.user:        
            def addCb(payload):
                def broadcastCb(payload):
                    res.callback(None)
                
                d2 = comm.broadcast('/user/' + req.user['id'], "{connected: \"%s\"}" % (session))
                d2.addCallback(broadcastCb)
                req.cookies.append(Cookie('user_chan', req.user['id'], path='/'))
        
            d1 = comm.addSub(session, '/user/' + req.user['id'])
            d1.addCallback(addCb)

        elif req.uchan:
            def remCb(payload):
                def broadcastCb(payload):
                    res.callback(None)
                
                d2 = comm.broadcast('/user/' + req.uchan, "{disconnected: \"%s\"}" % (session))
                d2.addCallback(broadcastCb)
                req.cookies.append(Cookie('user_chan', '', path='/'))
        
            d1 = comm.removeSub(session, '/user/' + req.uchan)
            d1.addCallback(remCb)
        
        else:
            res.callback(None)
            return None       
        
        return None
        
    else:
        res.callback(None)
        return None
Exemplo n.º 2
0
def http(req):
    if req.user or req.uchan:
        res = Deferred()

        if req.user:

            def addCb(payload):
                def broadcastCb(payload):
                    req.result = 'ok'
                    res.callback(None)

                d2 = comm.broadcast('/user/' + req.user['id'],
                                    "{connected: \"%s\"}" % (req.postpath[0]))
                d2.addCallback(broadcastCb)
                req.cookies.append(
                    Cookie('user_chan', req.user['id'], path='/'))

            d1 = comm.addSub(req.postpath[0], '/user/' + req.user['id'])
            d1.addCallback(addCb)

        elif req.uchan:

            def remCb(payload):
                def broadcastCb(payload):
                    req.result = 'ok'
                    res.callback(None)

                d2 = comm.broadcast(
                    '/user/' + req.uchan,
                    "{disconnected: \"%s\"}" % (req.postpath[0]))
                d2.addCallback(broadcastCb)
                req.cookies.append(Cookie('user_chan', '', path='/'))

            d1 = comm.removeSub(req.postpath[0], '/user/' + req.uchan)
            d1.addCallback(remCb)

        else:
            req.result = 'ok'
            return None

        return res

    else:
        req.result = 'error'
        return None
Exemplo n.º 3
0
def authCommSession(req, res, session):
    if req.user or req.uchan:
        if req.user:

            def addCb(payload):
                def broadcastCb(payload):
                    res.callback(None)

                d2 = comm.broadcast('/user/' + req.user['id'],
                                    "{connected: \"%s\"}" % (session))
                d2.addCallback(broadcastCb)
                req.cookies.append(
                    Cookie('user_chan', req.user['id'], path='/'))

            d1 = comm.addSub(session, '/user/' + req.user['id'])
            d1.addCallback(addCb)

        elif req.uchan:

            def remCb(payload):
                def broadcastCb(payload):
                    res.callback(None)

                d2 = comm.broadcast('/user/' + req.uchan,
                                    "{disconnected: \"%s\"}" % (session))
                d2.addCallback(broadcastCb)
                req.cookies.append(Cookie('user_chan', '', path='/'))

            d1 = comm.removeSub(session, '/user/' + req.uchan)
            d1.addCallback(remCb)

        else:
            res.callback(None)
            return None

        return None

    else:
        res.callback(None)
        return None
Exemplo n.º 4
0
Arquivo: auth.py Projeto: lzimm/360io
def http(req):
    if req.user or req.uchan:
        res = Deferred()
        
        if req.user:        
            def addCb(payload):
                def broadcastCb(payload):
                    req.result = 'ok'
                    res.callback(None)
                
                d2 = comm.broadcast('/user/' + req.user['id'], "{connected: \"%s\"}" % (req.postpath[0]))
                d2.addCallback(broadcastCb)
                req.cookies.append(Cookie('user_chan', req.user['id'], path='/'))
        
            d1 = comm.addSub(req.postpath[0], '/user/' + req.user['id'])
            d1.addCallback(addCb)

        elif req.uchan:
            def remCb(payload):
                def broadcastCb(payload):
                    req.result = 'ok'
                    res.callback(None)
                
                d2 = comm.broadcast('/user/' + req.uchan, "{disconnected: \"%s\"}" % (req.postpath[0]))
                d2.addCallback(broadcastCb)
                req.cookies.append(Cookie('user_chan', '', path='/'))
        
            d1 = comm.removeSub(req.postpath[0], '/user/' + req.uchan)
            d1.addCallback(remCb)
        
        else:
            req.result = 'ok'
            return None       
        
        return res
        
    else:
        req.result = 'error'
        return None