def loginMaster(self): def onSuccess(result): if 'token' not in result: log.debug('got login response without token') return 0 else: self.masterLoginToken = str(result['token']) self.cred_time = int(time.time()) log.debug('logged in with token %s' % self.masterLoginToken) return 1 def onFail(reason): log.error(reason) postData = {'username': self.login, 'password': self.password} d = rest_api.postData(self.uri, 'rest/login', postData, timeout=loginTimeout) d.addCallbacks(onSuccess,onFail) return d
def loginUser(self, username, password): def get_auth_tkt(result): def onTktSuccess(result, token_result): log.debug('got token result: %s' % token_result) log.debug('got auth_tkt response for %s: %s' % (self.name, cj)) return token_result, cj def onTktFail(reason, token_result): log.debug('got token result') log.debug(token_result) log.error('auth_tkt request failed') log.error(reason) return False, token_result token_result = result cj = {} headers = [] cj['auth_tkt'] = self._makeTicket(userid=username, remote_addr=local_ip) log.debug('requesting web auth with ticket: %s' % cj) #d = web_client.getPage(self.uri, headers, method='GET', cookies=cj) d = rest_api.getInfo(self.uri, '', headers, cookies=cj, timeout=loginTimeout) d.addCallback(onTktSuccess, token_result).addErrback(onTktFail, token_result) return d def onSuccess(result): if 'token' not in result: log.debug('got user login response without token') return False else: token = str(result['token']) cred_time = int(time.time()) log.debug('cookies: %s' % cj) log.debug('user logged in with token %s' % token) return (token, cred_time, cj) def onFail(reason): l = reason.trap(rest_api.LoginError) if l == rest_api.LoginError: pass else: log.error(reason) return False cj = {} cj['auth_tkt'] = self._makeTicket(userid=username, remote_addr=local_ip) postData = {'username': username, 'password': password} d = rest_api.postData(self.uri, 'rest/login', postData, headers={}, cookies=cj, timeout=loginTimeout) d.addCallbacks(onSuccess,onFail) return d