예제 #1
0
def twitter_connect_done(request):
    token = request.session.get('token', None)
    if not token:
        return render_to_response('socialauth/twitter_connect_error.html', {'token': True})
    token = oauth.OAuthToken.from_string(token)
    if token.key != request.GET.get('oauth_token', 'no-token'):
        return render_to_response('socialauth/twitter_connect_error.html', {'mismatch': True})
    token = twitter.get_authorized_token(token)

    # Actually login
    obj = twitter.is_authorized(token)
    
    if obj is None:
        return render_to_response('socialauth/twitter_connect_error.html', {'username': True})
    try: 
        twitter_profile = TwitterUserProfile.objects.get(\
                  screen_name=obj['screen_name'])
    except: 
        twitter_profile = TwitterUserProfile(screen_name=obj['screen_name'])
    
    twitter_profile.oauth_token = request.session['token']
    twitter_profile.oauth_token_key = token.key
    twitter_profile.oauth_token_secret = token.secret
    twitter_profile.user = request.user
    twitter_profile.save()
    #del request.session['token']
    return HttpResponseRedirect(reverse('newsfeed'))