Example #1
0
        def login(provider_id):
            """Starts the provider login OAuth flow"""

            if current_user.is_authenticated():
                return redirect(request.referrer or '/')

            callback_url = get_authorize_callback('/login/%s' % provider_id)
            display_name = get_display_name(provider_id)

            current_app.logger.debug('Starting login via %s account. Callback '
                                     'URL = %s' % (display_name, callback_url))

            post_login = request.form.get('next', get_post_login_redirect())
            session['post_oauth_login_url'] = post_login

            return get_remote_app(provider_id).authorize(callback_url)
Example #2
0
        def login(provider_id):
            """Starts the provider login OAuth flow"""

            if current_user.is_authenticated():
                return redirect(request.referrer or "/")

            callback_url = get_authorize_callback("/login/%s" % provider_id)
            display_name = get_display_name(provider_id)

            current_app.logger.debug(
                "Starting login via %s account. Callback " "URL = %s" % (display_name, callback_url)
            )

            post_login = request.form.get("next", get_post_login_redirect())
            session["post_oauth_login_url"] = post_login

            return get_remote_app(provider_id).authorize(callback_url)
Example #3
0
def _login_handler(provider_id, provider_user_id, oauth_response):
    """Shared method to handle the signin process 
    """
    if current_user.is_authenticated():
        return redirect("/")

    display_name = get_display_name(provider_id)

    current_app.logger.debug('Attempting login via %s with provider user '
                             '%s' % (display_name, provider_user_id))
    try:
        method = connection_datastore.get_connection_by_provider_user_id
        connection = method(provider_id, provider_user_id)
        user = user_datastore.with_id(connection.user_id)

        if login_user(user):
            redirect_url = session.pop(POST_OAUTH_LOGIN_SESSION_KEY,
                                       get_post_login_redirect())

            current_app.logger.debug('User logged in via %s. Redirecting to '
                                     '%s' % (display_name, redirect_url))

            return redirect(redirect_url)

        else:
            current_app.logger.info('Inactive local user attempted '
                                    'login via %s.' % display_name)
            do_flash("Inactive user", "error")

    except ConnectionNotFoundError:
        current_app.logger.info('Login attempt via %s failed because '
                                'connection was not found.' % display_name)

        msg = '%s account not associated with an existing user' % display_name
        do_flash(msg, 'error')
    """    
    except Exception, e:
        current_app.logger.error('Unexpected error signing in '
                                 'via %s: %s' % (display_name, e))
    """
    social_login_failed.send(current_app._get_current_object(),
                             provider_id=provider_id,
                             oauth_response=oauth_response)

    return redirect(login_manager.login_view)
Example #4
0
def _login_handler(provider_id, provider_user_id, oauth_response):
    """Shared method to handle the signin process 
    """
    if current_user.is_authenticated():
        return redirect("/")

    display_name = get_display_name(provider_id)

    current_app.logger.debug("Attempting login via %s with provider user " "%s" % (display_name, provider_user_id))
    try:
        method = connection_datastore.get_connection_by_provider_user_id
        connection = method(provider_id, provider_user_id)
        user = user_datastore.with_id(connection.user_id)

        if login_user(user):
            redirect_url = session.pop(POST_OAUTH_LOGIN_SESSION_KEY, get_post_login_redirect())

            current_app.logger.debug("User logged in via %s. Redirecting to " "%s" % (display_name, redirect_url))

            return redirect(redirect_url)

        else:
            current_app.logger.info("Inactive local user attempted " "login via %s." % display_name)
            do_flash("Inactive user", "error")

    except ConnectionNotFoundError:
        current_app.logger.info("Login attempt via %s failed because " "connection was not found." % display_name)

        msg = "%s account not associated with an existing user" % display_name
        do_flash(msg, "error")

    """    
    except Exception, e:
        current_app.logger.error('Unexpected error signing in '
                                 'via %s: %s' % (display_name, e))
    """
    social_login_failed.send(current_app._get_current_object(), provider_id=provider_id, oauth_response=oauth_response)

    return redirect(login_manager.login_view)