def ga_save_properties(user, org):

    tokens = session.pop('tokens')
    redirect_uri = session.get('redirect_uri')

    # PARSE HACKY FORM
    req_data = request_data()
    properties = []
    for k, v in req_data.items():
        prop = {'property': k.split('||')[0], 'profile': v}
        properties.append(prop)

    tokens['properties'] = properties

    ga_token = Auth.query\
        .filter_by(name='google-analytics', org_id=org.id)\
        .first()

    if not ga_token:

        # create settings object
        ga_token = Auth(org_id=org.id, name='google-analytics', value=tokens)

    else:
        ga_token.value = tokens

    db.session.add(ga_token)
    db.session.commit()

    # redirect to app
    if redirect_uri:
        uri = url.add_query_params(redirect_uri, auth_success='true')
        return redirect(uri)

    return jsonify(ga_token)
Exemplo n.º 2
0
def fb_callback():

    org_id = session.pop('org_id')
    redirect_uri = session.pop('redirect_uri')

    # check to make sure the user authorized the request
    if not 'code' in request.args:
        if not redirect_uri:
            raise AuthError('You did not authorize the request to facebook.')

        uri = url.add_query_params(redirect_uri, auth_success='false')
        return redirect(uri)

    # make a request for the access token credentials using code
    authorize_uri = url_for('auth_facebook.fb_callback', _external=True)
    data = dict(code=request.args['code'], redirect_uri=authorize_uri)

    # get a temporary access token
    temp_access_token = fb_oauth.get_access_token(data=data)
    tokens = fb_extend_oauth_token(temp_access_token)

    # upsert settings
    facebook_token = Auth.query\
        .filter_by(name='facebook', org_id=org_id)\
        .first()

    if not facebook_token:

        # create settings object
        facebook_token = Auth(
            org_id=org_id,
            name='facebook',
            value=tokens)

    else:
        facebook_token.value = tokens

    db.session.add(facebook_token)
    db.session.commit()

    if redirect_uri:
        uri = url.add_query_params(redirect_uri, auth_success='true')
        return redirect(uri)

    return jsonify(facebook_token)
Exemplo n.º 3
0
def fb_callback():

    org_id = session.pop('org_id')
    redirect_uri = session.pop('redirect_uri')

    # check to make sure the user authorized the request
    if not 'code' in request.args:
        if not redirect_uri:
            raise AuthError('You did not authorize the request to facebook.')

        uri = url.add_query_params(redirect_uri, auth_success='false')
        return redirect(uri)

    # make a request for the access token credentials using code
    authorize_uri = url_for('auth_facebook.fb_callback', _external=True)
    data = dict(code=request.args['code'], redirect_uri=authorize_uri)

    # get a temporary access token
    temp_access_token = fb_oauth.get_access_token(data=data)
    tokens = fb_extend_oauth_token(temp_access_token)

    # upsert settings
    facebook_token = Auth.query\
        .filter_by(name='facebook', org_id=org_id)\
        .first()

    if not facebook_token:

        # create settings object
        facebook_token = Auth(
            org_id=org_id,
            name='facebook',
            value=tokens)

    else:
        facebook_token.value = tokens

    db.session.add(facebook_token)
    db.session.commit()

    if redirect_uri:
        uri = url.add_query_params(redirect_uri, auth_success='true')
        return redirect(uri)

    return jsonify(facebook_token)
def ga_save_properties(user, org):

    tokens = session.pop('tokens')
    redirect_uri = session.get('redirect_uri')

    # PARSE HACKY FORM
    req_data = request_data()
    properties = []
    for k, v in req_data.items():
        prop = {
            'property': k.split('||')[0],
            'profile': v
        }
        properties.append(prop)

    tokens['properties'] = properties

    ga_token = Auth.query\
        .filter_by(name='google-analytics', org_id=org.id)\
        .first()

    if not ga_token:

        # create settings object
        ga_token = Auth(
            org_id=org.id,
            name='google-analytics',
            value=tokens)

    else:
        ga_token.value = tokens

    db.session.add(ga_token)
    db.session.commit()

    # redirect to app
    if redirect_uri:
        uri = url.add_query_params(redirect_uri, auth_success='true')
        return redirect(uri)

    return jsonify(ga_token)
Exemplo n.º 5
0
def twt_callback():

    # get redirect uri
    redirect_uri = session.pop('redirect_uri')

    if 'twitter_oauth' not in session:
        if redirect_uri:
            uri = url.add_query_params(redirect_uri, auth_success='false')
            return redirect(uri)
        raise RequestError(
            'An unkonwn error occurred during the twitter authentication process.')

    # get the request tokens from the session
    request_token, request_token_secret = session.pop('twitter_oauth')
    org_id = session.pop('org_id')

    # check to make sure the user authorized the request
    if not 'oauth_token' in request.args:
        if redirect_uri:
            uri = url.add_query_params(redirect_uri, auth_success='false')
            return redirect(uri)

        raise RequestError(
            'An unkonwn error occurred during the twitter authentication process.')

    # get stable authentication tokens
    creds = {
        'request_token': request_token,
        'request_token_secret': request_token_secret
    }
    params = {'oauth_verifier': request.args['oauth_verifier']}
    oauth_token, oauth_token_secret = twt_oauth.get_access_token(
        params=params, **creds)

    # store stable access tokens
    tokens = {
        'oauth_token': oauth_token,
        'oauth_token_secret': oauth_token_secret
    }

    # upsert settings
    twt_token = Auth.query\
        .filter_by(name='twitter', org_id=org_id)\
        .first()

    if not twt_token:

        # create settings object
        twt_token = Auth(
            org_id=org_id,
            name='twitter',
            value=tokens)

    else:
        twt_token.value = tokens

    db.session.add(twt_token)
    db.session.commit()

    # redirect to app
    if redirect_uri:
        uri = url.add_query_params(redirect_uri, auth_success='true')
        return redirect(uri)

    return jsonify(twt_token)
Exemplo n.º 6
0
def twt_callback():

    # get redirect uri
    redirect_uri = session.pop('redirect_uri')

    if 'twitter_oauth' not in session:
        if redirect_uri:
            uri = url.add_query_params(redirect_uri, auth_success='false')
            return redirect(uri)
        raise RequestError(
            'An unkonwn error occurred during the twitter authentication process.'
        )

    # get the request tokens from the session
    request_token, request_token_secret = session.pop('twitter_oauth')
    org_id = session.pop('org_id')

    # check to make sure the user authorized the request
    if not 'oauth_token' in request.args:
        if redirect_uri:
            uri = url.add_query_params(redirect_uri, auth_success='false')
            return redirect(uri)

        raise RequestError(
            'An unkonwn error occurred during the twitter authentication process.'
        )

    # get stable authentication tokens
    creds = {
        'request_token': request_token,
        'request_token_secret': request_token_secret
    }
    params = {'oauth_verifier': request.args['oauth_verifier']}
    oauth_token, oauth_token_secret = twt_oauth.get_access_token(params=params,
                                                                 **creds)

    # store stable access tokens
    tokens = {
        'oauth_token': oauth_token,
        'oauth_token_secret': oauth_token_secret
    }

    # upsert settings
    twt_token = Auth.query\
        .filter_by(name='twitter', org_id=org_id)\
        .first()

    if not twt_token:

        # create settings object
        twt_token = Auth(org_id=org_id, name='twitter', value=tokens)

    else:
        twt_token.value = tokens

    db.session.add(twt_token)
    db.session.commit()

    # redirect to app
    if redirect_uri:
        uri = url.add_query_params(redirect_uri, auth_success='true')
        return redirect(uri)

    return jsonify(twt_token)