def __doLogin(self, callback): if not LOGIN_STATE.canDoLogin(self.__loginState): callback(self.isLoggedOn()) return LOG_DEBUG('Clan gate login processing...') self.__loginState = LOGIN_STATE.LOGGING_IN nextLoginState = LOGIN_STATE.LOGGED_OFF LOG_DEBUG('Requesting spa token...') response = yield self._tokenRequester.request() if response and response.isValid(): pDbID = getPlayerDatabaseID() if response.getDatabaseID() == pDbID: LOG_DEBUG('Trying to login to the clan lib...') result = yield self.sendRequest( contexts.LogInCtx(pDbID, response.getToken())) if result.isSuccess(): nextLoginState = LOGIN_STATE.LOGGED_ON else: nextLoginState = LOGIN_STATE.LOGGED_OFF else: LOG_WARNING('There is error while getting spa token for clan gate', response) self.__loginState = nextLoginState if self.isLoggedOn(): self._clanCtrl.onStateUpdated() self.__processWaitingRequests() callback(self.isLoggedOn())
def __doLogin(self, callback): if not LOGIN_STATE.canDoLogin(self.__loginState): callback(self.isLoggedOn()) return else: self.__accessTokenData = None LOG_DEBUG('Clan gate login processing...') self.__loginState = LOGIN_STATE.LOGGING_IN nextLoginState = LOGIN_STATE.LOGGED_OFF LOG_DEBUG('Requesting spa token...') response = yield self._tokenRequester.request(allowDelay=True) if response and response.isValid(): pDbID = getPlayerDatabaseID() if response.getDatabaseID() == pDbID: LOG_DEBUG('Trying to login to the clan lib...') responseTime = time_utils.getCurrentTimestamp() result = yield self.sendRequest(contexts.LogInCtx(pDbID, response.getToken())) if result.isSuccess(): nextLoginState = LOGIN_STATE.LOGGED_ON data = result.getData() accessToken = data.get(_FIELD_ACCESS_TOKEN, None) if accessToken is not None: expiresIn = data.get(_FIELD_EXPIRES_IN, 0) if expiresIn is None: LOG_WARNING('Login success but ExpiresIn not defined! Use default value == 0!') else: responseTime += float(expiresIn) self.__accessTokenData = AccessTokenData(accessToken, responseTime) else: LOG_WARNING('Login success but AccessToken not defined!') else: nextLoginState = LOGIN_STATE.LOGGED_OFF else: LOG_WARNING('There is error while getting spa token for clan gate', response) self.__loginState = nextLoginState self.__clanSync = False self.__processWaitingRequests() callback(self.isLoggedOn()) return