Exemplo n.º 1
0
def twitter_login(request):
    reset_next_url(request)
    twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
    request_token = twitter.getRequestToken()
    request.session[REQUEST_TOKEN_SESSION_ID] = request_token
    login_url = twitter.getAuthenticationURL(request_token)
    return HttpResponseRedirect(login_url)
Exemplo n.º 2
0
def twitter_login_done(request):
    twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
    request_token = request.session[REQUEST_TOKEN_SESSION_ID]
    access_token = twitter.getAccessToken(request_token)

    user = authenticate(twitter_access_token=access_token)

    if not user:
        login_url = getattr(settings, 'LOGIN_URL', '/')
        return HttpResponseRedirect(login_url)

    login(request, user)

    next_url = get_next_url(request.session)

    return HttpResponseRedirect(next_url)