Ejemplo n.º 1
0
def confirmVerificationCode(phone_number, token):
    password = base64.b64encode(os.urandom(16))[:-2].decode('utf-8')

    signalingKey = os.urandom(52)
    registrationId = SystemRandom().randint(1, 16380 + 1)

    payload = {
        "signalingKey": base64.b64encode(signalingKey).decode('utf-8'),
        "supportsSms": False,
        "fetchesMessages": False,
        "registrationId": registrationId
    }

    r = requests.put(URL_BASE + '/v1/accounts/code/' + token,
                     headers=headers,
                     auth=(phone_number, password),
                     data=json.dumps(payload))

    if r.status_code in (400, 404):
        raise ServerError(r.status_code, 'The token was badly formatted.')
    elif r.status_code == 401:
        raise ServerError(r.status_code, 'Badly formatted basic auth.')
    elif r.status_code == 403:
        raise ServerError(r.status_code, 'Verification code was incorrect.')
    elif r.status_code == 413:
        raise ServerError(r.status_code, 'Rate limit exceeded.')
    elif r.status_code == 417:
        raise ServerError(r.status_code, 'Number already registered.')
    elif r.status_code in (200, 204):
        config.setConfigOption('phone_number', phone_number)
        config.setConfigOption('password', password)
        config.setConfigOption('signalingKey', signalingKey)
        config.setConfigOption('registrationId', str(registrationId))
        return
Ejemplo n.º 2
0
def confirmVerificationCode(phone_number, token):
    password = base64.b64encode(os.urandom(16))[:-2].decode('utf-8')

    signalingKey = os.urandom(52)
    registrationId = SystemRandom().randint(1, 16380 + 1)

    payload = {
        "signalingKey" : base64.b64encode(signalingKey).decode('utf-8'),
        "supportsSms" : False,
        "fetchesMessages" : False,
        "registrationId" : registrationId
    }

    r = requests.put( URL_BASE + '/v1/accounts/code/' + token,
                     headers=headers,
                     auth=(phone_number, password),
                     data=json.dumps(payload) )

    if r.status_code in (400 , 404):
        raise ServerError(r.status_code, 'The token was badly formatted.')
    elif r.status_code == 401:
        raise ServerError(r.status_code, 'Badly formatted basic auth.')
    elif r.status_code == 403:
        raise ServerError(r.status_code, 'Verification code was incorrect.')
    elif r.status_code == 413:
        raise ServerError(r.status_code, 'Rate limit exceeded.')
    elif r.status_code == 417:
        raise ServerError(r.status_code, 'Number already registered.')
    elif r.status_code in (200, 204):
        config.setConfigOption('phone_number', phone_number)
        config.setConfigOption('password', password)
        config.setConfigOption('signalingKey', signalingKey)
        config.setConfigOption('registrationId', str(registrationId))
        return
Ejemplo n.º 3
0
def configGCM(email, password, app=app, senderId=senderId):
    gapi = googleplayapi.GooglePlayAPI(email, password)
    androidId = gapi.getAndroidId()
    securityToken = gapi.getSecurityToken()
    regid = gapi.register(app, senderId)

    config.setConfigOption('gcmandroidId', str(androidId))
    config.setConfigOption('gcmsecurityToken', str(securityToken))
    config.setConfigOption('gcmregid', regid)
Ejemplo n.º 4
0
def configGCM(email, password, app=app, senderId=senderId):
    gapi = googleplayapi.GooglePlayAPI(email, password)
    androidId = gapi.getAndroidId()
    securityToken = gapi.getSecurityToken()
    regid = gapi.register(app, senderId)

    config.setConfigOption('gcmandroidId', str(androidId))
    config.setConfigOption('gcmsecurityToken', str(securityToken))
    config.setConfigOption('gcmregid', regid)