Ejemplo n.º 1
0
def checkLogin():
    if not isNull(TOKEN.accessToken):
        #print('Checking Access Token...') #add to translations
        msg, check = API.verifyAccessToken(TOKEN.accessToken)
        if check == True:
            Printf.info(
                LANG.MSG_VALID_ACCESSTOKEN.format(
                    displayTime(int(TOKEN.expiresAfter - time.time()))))
            return
        else:
            Printf.info(LANG.MSG_INVAILD_ACCESSTOKEN)
            msg, check = API.refreshAccessToken(TOKEN.refreshToken)
            if check == True:
                Printf.success(
                    LANG.MSG_VALID_ACCESSTOKEN.format(
                        displayTime(int(API.key.expiresIn))))
                TOKEN.userid = API.key.userId
                TOKEN.countryCode = API.key.countryCode
                TOKEN.accessToken = API.key.accessToken
                TOKEN.expiresAfter = time.time() + int(API.key.expiresIn)
                TokenSettings.save(TOKEN)
                return
            else:
                Printf.err(msg)
                tmp = TokenSettings()  #clears saved tokens
                TokenSettings.save(tmp)
    login()
    return
def loginByWeb():
    start = time.time()
    elapsed = 0
    while elapsed < API.key.authCheckTimeout:
        elapsed = time.time() - start
        msg, check = API.checkAuthStatus()
        if not check:
            if msg == "pending":
                time.sleep(API.key.authCheckInterval + 1)
                continue
            return False
        if check:
            Printf.success(
                LANG.MSG_VALID_ACCESSTOKEN.format(
                    displayTime(int(API.key.expiresIn))))
            TOKEN.userid = API.key.userId
            TOKEN.countryCode = API.key.countryCode
            TOKEN.accessToken = API.key.accessToken
            TOKEN.refreshToken = API.key.refreshToken
            TOKEN.expiresAfter = time.time() + int(API.key.expiresIn)
            TokenSettings.save(TOKEN)
            return True

    Printf.err(LANG.AUTH_TIMEOUT)
    return False
def loginByConfig():
    if aigpy.stringHelper.isNull(TOKEN.accessToken):
        return False

    msg, check = API.verifyAccessToken(TOKEN.accessToken)
    if check:
        Printf.info(
            LANG.MSG_VALID_ACCESSTOKEN.format(
                displayTime(int(TOKEN.expiresAfter - time.time()))))
        API.key.countryCode = TOKEN.countryCode
        API.key.userId = TOKEN.userid
        API.key.accessToken = TOKEN.accessToken
        return True

    Printf.info(LANG.MSG_INVAILD_ACCESSTOKEN)
    msg, check = API.refreshAccessToken(TOKEN.refreshToken)
    if check:
        Printf.success(
            LANG.MSG_VALID_ACCESSTOKEN.format(
                displayTime(int(API.key.expiresIn))))
        TOKEN.userid = API.key.userId
        TOKEN.countryCode = API.key.countryCode
        TOKEN.accessToken = API.key.accessToken
        TOKEN.expiresAfter = time.time() + int(API.key.expiresIn)
        TokenSettings.save(TOKEN)
        return True
    else:
        tmp = TokenSettings()  # clears saved tokens
        TokenSettings.save(tmp)
        return False
Ejemplo n.º 4
0
def login():
    print(LANG.AUTH_START_LOGIN)
    msg, check = API.getDeviceCode()
    if check == False:
        Printf.err(msg)
        return

    print(LANG.AUTH_LOGIN_CODE.format(green(API.key.userCode)))
    print(LANG.AUTH_NEXT_STEP.format(green(API.key.verificationUrl), yellow(displayTime(API.key.authCheckTimeout))))
    print(LANG.AUTH_WAITING)
    start = time.time()
    elapsed = 0
    while elapsed < API.key.authCheckTimeout:
        elapsed = time.time() - start
        # print("Check auth status...")
        msg, check = API.checkAuthStatus()
        if check == False:
            if msg == "pending":
                time.sleep(API.key.authCheckInterval + 1)
                continue
            Printf.err(msg)
            break
        if check == True:
            Printf.success(LANG.MSG_VALID_ACCESSTOKEN.format(displayTime(int(API.key.expiresIn))))
            TOKEN.userid = API.key.userId
            TOKEN.countryCode = API.key.countryCode
            TOKEN.accessToken = API.key.accessToken
            TOKEN.refreshToken = API.key.refreshToken
            TOKEN.expiresAfter = time.time() + int(API.key.expiresIn)
            TokenSettings.save(TOKEN)
            break
    if elapsed >= API.key.authCheckTimeout:
        Printf.err(LANG.AUTH_TIMEOUT)
    return
Ejemplo n.º 5
0
def setAccessToken():
    while True:
        print("-------------AccessToken---------------")
        token = Printf.enter("accessToken('0' go back):")
        if token == '0':
            return
        msg, check = API.loginByAccessToken(token, TOKEN.userid)
        if check == False:
            Printf.err(msg)
            continue
        break

    print("-------------RefreshToken---------------")
    refreshToken = Printf.enter("refreshToken('0' to skip):")
    if refreshToken == '0':
        refreshToken = TOKEN.refreshToken

    TOKEN.assesstoken = token
    TOKEN.refreshToken = refreshToken
    TOKEN.expiresAfter = 0
    TokenSettings.save(TOKEN)