コード例 #1
0
    def new_token(self, internal=True):
        password = self._decryptedpw()
        data = self.webrequest(self.baseAuthUrl + self.authUrl,
                               internal=internal,
                               data=WebFormData(Email=self.name,
                                                Passwd=password,
                                                PersistentCookie='false',
                                                accountType='HOSTED_OR_GOOGLE',
                                                skipvpage='true'))
        if not data:
            return False

        if not data or data.find('Error=badauth') != -1:
            log.warning('Invalid username or password: badauth token')
            self.bad_pw()
            return False
        d1 = dict(b.split('=') for b in data.split())
        d1.update(Session='true', skipvpage='true', service='gaia')
        token = self.webrequest(self.baseAuthUrl + self.tokenUrl,
                                WebFormData(**d1))
        token = token.strip()
        if not internal:
            self.external_token = token

        return token
コード例 #2
0
    def __call__(self, method, callback=None, **kwds):
        callargs = {
            'session_token': self.session_token,
            'application_id': 'user',
            'format': 'json'
        }
        callargs.update(method=method)
        callargs.update(kwds)

        def success(req, resp):
            resp = resp.read()
            json = simplejson.loads(resp)
            if json['stat'] == 'ok':
                callback.success(json['result'] if 'result' in
                                 json else json['results'])
            elif json['stat'] == 'fail':
                raise Exception('API call failed %r', json)
            elif json['stat'] == 'nobot':
                d = {
                    'x*=': (lambda x, y: x * y),
                    'x-=': (lambda x, y: x - y),
                    'x+=': (lambda x, y: x + y),
                    'x=x%': (lambda x, y: x % y)
                }

                result = json['result']

                fnc = result['jsfunc'].replace('(function(){var ', '').replace(
                    'return x;})()', '')
                init = fnc.split(';')[0]
                rest = fnc.split(';')[1:]
                x = int(init[2:])
                for val in rest:
                    for key in d:
                        if val.startswith(key):
                            y = int(val[len(key):])
                            x = d[key](x, y)

                self.security.nobot.submitAnswer(answer=x,
                                                 origCallObj=simplejson.dumps(
                                                     result['origCallObj']),
                                                 callback=callback)

        self.opener.open(self.API_URL,
                         WebFormData(**callargs),
                         success=success,
                         error=callback.error)
コード例 #3
0
ファイル: TaggedRealtime.py プロジェクト: sgricci/digsby
    def __call__(self, method, callback=None, **kwds):
        callargs = {
            'session_token': self.session_token,
            'user_id': self.user_id
        }
        callargs.update(method=method)
        if 'event_types' in kwds:
            kwds['event_types'] = simplejson.dumps(kwds['event_types'])
        callargs.update(kwds)

        req = AsyncHttp.HTTPRequest(self.REALTIME_URL, WebFormData(**callargs),
                                    {'X-T-Uid': self.user_id})

        def success(req, resp):
            resp = resp.read()

            # TODO temporary until prod nodeServer gets updated
            if resp.startswith('undefined'):
                resp = resp[10:-2]

            json = simplejson.loads(resp)
            data = json['data']

            if method == 'query_event_id':
                if json['status'] == 'ok':
                    log.info('Realtime initialization successful')
                    callback.success(data)
                else:
                    log.warning('Realtime initialization failed')
                    callback.error()

            elif method == 'register_client':
                if 'success' in json:
                    log.info('Realtime pushed data %r', data)
                    callback.success(data)
                elif data[
                        'message'] == 'Authentication failed: Bad session token.':
                    log.warning(
                        "We're likely active on a browser, hop on their userObj"
                    )
                    callback.error()
                else:
                    log.warning('Realtime register failed %r', data)
                    callback.error()

        self.opener.open(req, success=success, error=callback.error)