def do_final_redirect()

in pulseapi/users/views.py [0:0]


def do_final_redirect(state, loggedin, msg):
    """
    As final step in the oauth callback process, redirect the user either to
    the api root, or if there was an original_url to indicate where the user
    was when they started the oauth process, move them back to that url instead.

    This redirect is accompanied by a URL query pair "loggedin=..." which can
    either be 'true' or 'false', and can be used to determine whether the login
    attempd succeeded or not.
    """
    redirect_url = '/'

    # Do we need to redirect the user to some explicit URL after login?
    try:
        validator = URLValidator()
        validator(state)
        redirect_url = state
    except ValidationError:
        pass

    print(f'want to redirect to {redirect_url}')

    # Add the result of the login attempt to the redirect URL as query pair
    if '?' in redirect_url:
        redirect_url += '&'
    else:
        redirect_url += '?'
    redirect_url += 'loggedin=' + str(loggedin)

    return redirect(redirect_url)