Esempio n. 1
0
def load_common_context():
    return common_context(
        app.config['SOCIAL_AUTH_AUTHENTICATION_BACKENDS'],
        load_strategy(),
        getattr(g, 'user', None),
        app.config.get('SOCIAL_AUTH_GOOGLE_PLUS_KEY')
    )
Esempio n. 2
0
def _get_stats():
    social_auth_user = g.user.social_auth.get()
    # Coinbase returns `expires_in` but PSA expects `expires`
    social_auth_user.extra_data['expires'] = social_auth_user.extra_data[
        'expires_in']
    access_token = social_auth_user.get_access_token(load_strategy())
    return get_coinbase_stats(access_token)
Esempio n. 3
0
def require_email():
    strategy = load_strategy()
    partial_token = request.args.get('partial_token')
    partial = strategy.partial_load(partial_token)
    return render_template('home.html',
                           email_required=True,
                           partial_backend_name=partial.backend,
                           partial_token=partial_token)
Esempio n. 4
0
def stats_api():
    social_auth_user = g.user.social_auth.get()
    # Coinbase returns `expires_in` but PSA expects `expires`
    social_auth_user.extra_data['expires'] = social_auth_user.extra_data[
        'expires_in']
    access_token = social_auth_user.get_access_token(load_strategy())
    currency = request.args.get('currency', 'total').lower()
    period = request.args.get('period', 'hour').lower()
    if currency not in CURRENCIES or period not in PERIODS:
        response = {'error': True}
    else:
        response = get_coinbase_stats(access_token, currency, period)
    return jsonify(response)
 def run_pipeline(self, BackendClass):
     with self.test_request_context():
         strategy = load_strategy()
         backend = BackendClass(strategy=strategy)
         pipeline = strategy.get_pipeline(backend)
         result = backend.run_pipeline(pipeline,
                                       pipeline_index=0,
                                       backend=backend,
                                       is_new=False,
                                       response=self.response,
                                       storage=strategy.storage,
                                       strategy=strategy,
                                       user=None)
         return result
Esempio n. 6
0
 def refresh_peam_access_token_if_needed(self):
     user_social_auth = get_user_social_auth(self.id)
     if not user_social_auth:
         return
     # FTR there is no extra_data['expires'] nor extra_data['expires_in'] :-(
     token_age_in_seconds = int(
         time.time()) - user_social_auth.extra_data['auth_time']
     # The PEAMU token is valid for 6 months supposedly.
     # We refresh it no more than once every few hours to avoid flooding the PEAM API with too many requests.
     # This way the user will only get disconnected when he did not use LBB for at least 6 months.
     if token_age_in_seconds >= settings.REFRESH_PEAM_TOKEN_NO_MORE_THAN_ONCE_EVERY_SECONDS:
         try:
             strategy = load_strategy()
             user_social_auth.refresh_token(strategy)
         except requests.HTTPError as e:
             if e.response.status_code == 400:
                 raise TokenRefreshFailure
             raise
Esempio n. 7
0
def stats_api():
    social_auth_user = g.user.social_auth.get()
    # Coinbase returns `expires_in` but PSA expects `expires`
    social_auth_user.extra_data['expires'] = social_auth_user.extra_data[
        'expires_in']
    access_token = social_auth_user.get_access_token(load_strategy())
    currency = request.args.get('currency', 'total').lower()
    period = request.args.get('period', 'hour').lower()
    redirect_url = url_for('error')
    if currency not in CURRENCIES or period not in PERIODS:
        response = {'error': True}
    else:
        try:
            response = get_coinbase_stats(access_token, currency, period)
        except Exception as e:
            logger.exception('APIError')
            if isinstance(e, APIError) and e.id == 'revoked_token':
                redirect_url = url_for('logout')
            if isinstance(e, HTTPError) and e.response.status_code == 401:
                redirect_url = url_for('logout')
            response = {'error': True}
    response['redirect_url'] = redirect_url

    return jsonify(response)
Esempio n. 8
0
def load_common_context():
    return common_context(
        app.config['SOCIAL_AUTH_AUTHENTICATION_BACKENDS'],
        load_strategy(),
        getattr(g, 'user', None)
    )