def prepare_app():
    ''' Prepare app, ask Heroku to authenticate, return to /callback-heroku.
    '''
    view_id, website_url = request.form.get('property').split(' ', 1)
    name, email = request.form.get('name'), request.form.get('email')
    client_id = request.form.get('client_id')
    client_secret = request.form.get('client_secret')
    refresh_token = request.form.get('refresh_token')

    organisation_name = request.form.get('organisation_name', 'LG Analytics Dashboard')
    shortcut_icon = request.form.get('shortcut_icon', '/favicon.ico')
    theme_colour = request.form.get('theme_colour', '#212121')
    title_filter = request.form.get('title_filter', ' | ')
    
    # Make sure these vars have values
    
    if not (organisation_name and organisation_name.strip()):
        organisation_name = 'LG Analytics Dashboard'
    
    if not (shortcut_icon and shortcut_icon.strip()):
        shortcut_icon = '/favicon.ico'
    
    if not (theme_colour and theme_colour.strip()):
        theme_colour = '#212121'
    
    if not (title_filter and title_filter.strip()):
        title_filter = ' | '
    
    env = dict(LANG='en_US.UTF-8', RACK_ENV='production',
               GA_VIEW_ID=view_id, GA_WEBSITE_URL=website_url,
               CLIENT_ID=client_id, CLIENT_SECRET=client_secret,
               REFRESH_TOKEN=refresh_token,
               ORGANISATION_NAME=organisation_name,
               SHORTCUT_ICON=shortcut_icon, THEME_COLOUR=theme_colour,
               TITLE_FILTER=title_filter)
    
    tarpath = prepare_tarball(display_screen_tarball_url,
                              dict(name='Display Screen', env=env))
    
    logger.debug('GET /prepare-app {} {}'.format(app.config, env))
    
    with psycopg2.connect(app.config['SQLALCHEMY_DATABASE_URI']) as connection:
        with connection.cursor() as cursor:
            tarball_id = builders.add_connection(cursor, email, name, website_url, tarpath)
            builders.set_connection_datum(cursor, tarball_id, 'google name', name)
            builders.set_connection_datum(cursor, tarball_id, 'google email', email)
            builders.set_connection_datum(cursor, tarball_id, 'google url', website_url)
    
    client_id, _, redirect_uri = heroku_client_info(request)
    
    query_string = urlencode(dict(client_id=client_id, redirect_uri=redirect_uri,
                                  response_type='code', scope='global',
                                  state=str(tarball_id)))
    
    logger.debug('POST /prepare-app redirect {}?{}'.format(heroku_authorize_url, query_string))
    
    return redirect(heroku_authorize_url + '?' + query_string)
Esempio n. 2
0
def prepare_app():
    ''' Prepare app, ask Heroku to authenticate, return to /callback-heroku.
    '''
    view_id, website_url = request.form.get('property').split(' ', 1)
    name, email = request.form.get('name'), request.form.get('email')
    client_id = request.form.get('client_id')
    client_secret = request.form.get('client_secret')
    refresh_token = request.form.get('refresh_token')

    env = dict(LANG='en_US.UTF-8',
               RACK_ENV='production',
               GA_VIEW_ID=view_id,
               GA_WEBSITE_URL=website_url,
               CLIENT_ID=client_id,
               CLIENT_SECRET=client_secret,
               REFRESH_TOKEN=refresh_token)

    tarpath = prepare_tarball(display_screen_tarball_url,
                              dict(name='Display Screen', env=env))

    with psycopg2.connect(app.config['SQLALCHEMY_DATABASE_URI']) as connection:
        with connection.cursor() as cursor:
            tarball_id = builders.add_connection(cursor, email, name,
                                                 website_url, tarpath)
            builders.set_connection_datum(cursor, tarball_id, 'google name',
                                          name)
            builders.set_connection_datum(cursor, tarball_id, 'google email',
                                          email)
            builders.set_connection_datum(cursor, tarball_id, 'google url',
                                          website_url)

    client_id, _, redirect_uri = heroku_client_info(request)

    query_string = urlencode(
        dict(client_id=client_id,
             redirect_uri=redirect_uri,
             response_type='code',
             scope='global',
             state=str(tarball_id)))

    logger.debug('POST /prepare-app redirect {}?{}'.format(
        heroku_authorize_url, query_string))

    return redirect(heroku_authorize_url + '?' + query_string)
def prepare_app():
    """ Prepare app, ask Heroku to authenticate, return to /callback-heroku.
    """
    view_id, website_url = request.form.get("property").split(" ", 1)
    name, email = request.form.get("name"), request.form.get("email")
    client_id = request.form.get("client_id")
    client_secret = request.form.get("client_secret")
    refresh_token = request.form.get("refresh_token")

    env = dict(
        LANG="en_US.UTF-8",
        RACK_ENV="production",
        GA_VIEW_ID=view_id,
        GA_WEBSITE_URL=website_url,
        CLIENT_ID=client_id,
        CLIENT_SECRET=client_secret,
        REFRESH_TOKEN=refresh_token,
    )

    tarpath = prepare_tarball(display_screen_tarball_url, dict(name="Display Screen", env=env))

    with psycopg2.connect(app.config["SQLALCHEMY_DATABASE_URI"]) as connection:
        with connection.cursor() as cursor:
            tarball_id = builders.add_connection(cursor, email, name, website_url, tarpath)
            builders.set_connection_datum(cursor, tarball_id, "google name", name)
            builders.set_connection_datum(cursor, tarball_id, "google email", email)
            builders.set_connection_datum(cursor, tarball_id, "google url", website_url)

    client_id, _, redirect_uri = heroku_client_info(request)

    query_string = urlencode(
        dict(
            client_id=client_id, redirect_uri=redirect_uri, response_type="code", scope="global", state=str(tarball_id)
        )
    )

    logger.debug("POST /prepare-app redirect {}?{}".format(heroku_authorize_url, query_string))

    return redirect(heroku_authorize_url + "?" + query_string)
def prepare_app():
    ''' Prepare app, ask Heroku to authenticate, return to /callback-heroku.
    '''
    view_id, website_url = request.form.get('property').split(' ', 1)
    name, email = request.form.get('name'), request.form.get('email')
    client_id = request.form.get('client_id')
    client_secret = request.form.get('client_secret')
    refresh_token = request.form.get('refresh_token')

    organisation_name = request.form.get('organisation_name',
                                         'LG Analytics Dashboard')
    shortcut_icon = request.form.get('shortcut_icon', '/favicon.ico')
    theme_colour = request.form.get('theme_colour', '#212121')
    title_filter = request.form.get('title_filter', ' | ')

    # Make sure these vars have values

    if not (organisation_name and organisation_name.strip()):
        organisation_name = 'LG Analytics Dashboard'

    if not (shortcut_icon and shortcut_icon.strip()):
        shortcut_icon = '/favicon.ico'

    if not (theme_colour and theme_colour.strip()):
        theme_colour = '#212121'

    if not (title_filter and title_filter.strip()):
        title_filter = ' | '

    env = dict(LANG='en_US.UTF-8',
               RACK_ENV='production',
               GA_VIEW_ID=view_id,
               GA_WEBSITE_URL=website_url,
               CLIENT_ID=client_id,
               CLIENT_SECRET=client_secret,
               REFRESH_TOKEN=refresh_token,
               ORGANISATION_NAME=organisation_name,
               SHORTCUT_ICON=shortcut_icon,
               THEME_COLOUR=theme_colour,
               TITLE_FILTER=title_filter)

    tarpath = prepare_tarball(display_screen_tarball_url,
                              dict(name='Display Screen', env=env))

    logger.debug('GET /prepare-app {} {}'.format(app.config, env))

    with psycopg2.connect(app.config['SQLALCHEMY_DATABASE_URI']) as connection:
        with connection.cursor() as cursor:
            tarball_id = builders.add_connection(cursor, email, name,
                                                 website_url, tarpath)
            builders.set_connection_datum(cursor, tarball_id, 'google name',
                                          name)
            builders.set_connection_datum(cursor, tarball_id, 'google email',
                                          email)
            builders.set_connection_datum(cursor, tarball_id, 'google url',
                                          website_url)

    client_id, _, redirect_uri = heroku_client_info(request)

    query_string = urlencode(
        dict(client_id=client_id,
             redirect_uri=redirect_uri,
             response_type='code',
             scope='global',
             state=str(tarball_id)))

    logger.debug('POST /prepare-app redirect {}?{}'.format(
        heroku_authorize_url, query_string))

    return redirect(heroku_authorize_url + '?' + query_string)