def authenticate(self, twitter_id=None): try: return TwitterProfile.objects( twitter_id=twitter_id #site=Site.objects.get_current() ).user except TwitterProfile.DoesNotExist: return None
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.objects(twitter_id=user_info['id']) except TwitterProfile.DoesNotExist: # There can only be one profile! profile = TwitterProfile(user=request.user, twitter_id=user_info['id']) profile.save() return HttpResponseRedirect(_get_next(request)) user = getuser(twitter_id=user_info['id']) if user is None: profile = TwitterProfile(twitter_id=user_info['id']) user = User() 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))