Beispiel #1
0
def return_(request):
    """Twitter OAuth return URL"""
    unauthed_token = request.session.get("unauthed_token", None)
    if not unauthed_token:
        return HttpResponse("No un-authed token cookie")
    token = oauth.OAuthToken.from_string(unauthed_token)
    if token.key != request.GET.get("oauth_token", "no-token"):
        return HttpResponse("Something went wrong! Tokens do not match")
    access_token = exchange_request_token_for_access_token(CONSUMER, create_connection(), token)
    request.session["access_token"] = access_token.to_string()
    # if the twitter user already exists and has a complete profile
    # redirect them to their profile page
    try:
        user = TwitterUser.objects.get(token=access_token.to_string()).user
        try:
            person = user.get_profile()
            # log in as this user
            from django.contrib.auth import load_backend, login

            for backend in settings.AUTHENTICATION_BACKENDS:
                if user == load_backend(backend).get_user(user.pk):
                    user.backend = backend
            if hasattr(user, "backend"):
                login(request, user)
            return HttpResponseRedirect(person.get_absolute_url())
        except KungfuPerson.DoesNotExist:
            pass
    except TwitterUser.DoesNotExist:
        pass
    return HttpResponseRedirect(reverse("twitter_signup"))
Beispiel #2
0
def return_(request):
    """Twitter OAuth return URL"""
    unauthed_token = request.session.get('unauthed_token', None)
    if not unauthed_token:
        return HttpResponse("No un-authed token cookie")
    token = oauth.OAuthToken.from_string(unauthed_token)
    if token.key != request.GET.get('oauth_token', 'no-token'):
        return HttpResponse("Something went wrong! Tokens do not match")
    access_token = exchange_request_token_for_access_token(
        CONSUMER, create_connection(), token)
    request.session['access_token'] = access_token.to_string()
    # if the twitter user already exists and has a complete profile
    # redirect them to their profile page
    try:
        user = TwitterUser.objects.get(token=access_token.to_string()).user
        try:
            person = user.get_profile()
            # log in as this user
            from django.contrib.auth import load_backend, login
            for backend in settings.AUTHENTICATION_BACKENDS:
                if user == load_backend(backend).get_user(user.pk):
                    user.backend = backend
            if hasattr(user, 'backend'):
                login(request, user)
            return HttpResponseRedirect(person.get_absolute_url())
        except KungfuPerson.DoesNotExist:
            pass
    except TwitterUser.DoesNotExist:
        pass
    return HttpResponseRedirect(reverse('twitter_signup'))
Beispiel #3
0
def auth(request):
    """Sends the user to twitter's auth page"""
    token = get_unauthorised_request_token(CONSUMER, create_connection())
    auth_url = get_authorisation_url(CONSUMER, token)
    response = HttpResponseRedirect(auth_url)
    request.session["unauthed_token"] = token.to_string()
    return response
Beispiel #4
0
def auth(request):
    """Sends the user to twitter's auth page"""
    token = get_unauthorised_request_token(CONSUMER, create_connection())
    auth_url = get_authorisation_url(CONSUMER, token)
    response = HttpResponseRedirect(auth_url)
    request.session['unauthed_token'] = token.to_string()
    return response