def twitter(request, account_inactive_template='socialregistration/account_inactive.html', extra_context=dict()):
    """
    Actually setup/login an account relating to a twitter user after the oauth
    process is finished successfully
    """
    client = OAuthTwitter(
        request, settings.TWITTER_CONSUMER_KEY,
        settings.TWITTER_CONSUMER_SECRET_KEY,
        settings.TWITTER_REQUEST_TOKEN_URL,
    )

    user_info = client.get_user_info()

    if request.user.is_authenticated():
        # Handling already logged in users connecting their accounts
        try:
            profile = TwitterProfile.all().filter('twitter_id = ',user_info['id']).fetch(1)[0]
        except IndexError: # There can only be one profile!
            profile = TwitterProfile(user=request.user, 
                twitter_id=user_info['id'], 
                username=user_info['screen_name'], 
                real_name=user_info['name'],
                pic_url = user_info['profile_image_url'],
            )
            profile.save()

        return HttpResponseRedirect(_get_next(request))

    user = authenticate(twitter_id=user_info['id'])

    if user is None:
        profile = TwitterProfile(                
            twitter_id=user_info['id'], 
            username=user_info['screen_name'], 
            real_name=user_info['name'],
            pic_url = user_info['profile_image_url'],
        )

        user = User(username=profile.real_name)
        request.session['social_suggested_username'] = user_info['screen_name']
        request.session['socialregistration_profile'] = profile
        request.session['socialregistration_user'] = user
        request.session['next'] = _get_next(request)
        return HttpResponseRedirect(reverse('socialregistration_setup'))

    if not user.is_active:
        return render_to_response(
            account_inactive_template,
            extra_context,
            context_instance=RequestContext(request)
        )

    login(request, user)

    return HttpResponseRedirect(_get_next(request))
Ejemplo n.º 2
0
    def authenticate(self, twitter_id=None):
        try:
            twitter_profile = TwitterProfile.all()
            twitter_profile.filter('twitter_id = ', twitter_id)
            #twitter_profile.filter('site = ',Site.objects.get_current())
            twitter_profile = twitter_profile.fetch(1)
            auth_user = twitter_profile[0].user

            return auth_user
            #TwitterProfile.objects.get(
            #twitter_id=twitter_id,
            #site=Site.objects.get_current()
            #).user
        except:
            return None
    def authenticate(self, twitter_id=None):
        try:
            twitter_profile = TwitterProfile.all()
            twitter_profile.filter('twitter_id = ',twitter_id)
            #twitter_profile.filter('site = ',Site.objects.get_current())
            twitter_profile = twitter_profile.fetch(1)
            auth_user = twitter_profile[0].user

            return auth_user
                #TwitterProfile.objects.get(
                #twitter_id=twitter_id,
                #site=Site.objects.get_current()
            #).user
        except:
            return None
Ejemplo n.º 4
0
 def authenticate(self, twitter_id=None):
     return TwitterProfile.all().filter('twitter_id =', twitter_id).get()