Exemplo n.º 1
0
 def authenticate(self,
                  twitter_id=None,
                  username=None,
                  token=None,
                  secret=None):
     # find or create the user
     try:
         info = TwitterInfo.objects.get(id=twitter_id)
         # make sure the screen name is current
         if info.name != username:
             info.name = username
             info.save()
         user = info.user
     except TwitterInfo.DoesNotExist:
         email = "*****@*****.**" % username
         user = User.objects.create_user(settings.USERS_FORMAT % username,
                                         email)
         user.save()
         info = TwitterInfo(user=user,
                            name=username,
                            id=twitter_id,
                            token=token,
                            secret=secret)
         info.save()
     return user
Exemplo n.º 2
0
 def authenticate(self, twitter_id=None, username=None, token=None, secret=None):
     # find or create the user
     try:
         info = TwitterInfo.objects.get(id=twitter_id)
         # make sure the screen name is current
         if info.name != username:
             info.name = username
             info.save()
         user = info.user
     except TwitterInfo.DoesNotExist:
         email    = "*****@*****.**" % username
         user     = User.objects.create_user(settings.USERS_FORMAT % username, email)
         user.save()
         info = TwitterInfo(user=user, name=username, id=twitter_id, token=token, secret=secret)
         info.save()
     return user
Exemplo n.º 3
0
    def authenticate(self, twitter_id=None, screen_name=None, token=None, secret=None, user_info=None):
        # find or create the user

        def copy_info(user_info, info):
            # There must be a better way of doing this. I don't know :$
            if user_info['lang']: info.lang = user_info['lang']
            if user_info['created_at']: info.joined_on = datetime.strptime(user_info['created_at'], "%a %b %d %H:%M:%S +0000 %Y")
            if user_info['url']: info.url = user_info['url']
            if user_info['profile_image_url']: info.profile_image = user_info['profile_image_url']
            if user_info['protected']: info.protected = user_info['protected']
            if user_info['name']: info.name = user_info['name']
            if user_info['description']: info.description = user_info['description']
            if user_info['statuses_count']: info.statuses_count = user_info['statuses_count']
            if user_info['favourites_count']: info.favourites_count = user_info['favourites_count']
            if user_info['followers_count']: info.followers_count = user_info['followers_count']
            if user_info['friends_count']: info.friends_count = user_info['friends_count']
            if user_info['utc_offset']: info.utc_offset = user_info['utc_offset']
            if user_info['location']: info.location = user_info['location']
            if user_info['time_zone']: info.time_zone = user_info['time_zone']

        try:
            info = TwitterInfo.objects.get(id=twitter_id)
            # make sure the screen name is current
            if info.screen_name != screen_name:
                info.screen_name = screen_name
            if user_info:
                copy_info(user_info, info)
            info.save()
            user = info.user
        except TwitterInfo.DoesNotExist:
            email    = "*****@*****.**" % screen_name
            username = settings.USERS_FORMAT % screen_name
            try:
                user = User.objects.get(username__exact=username)
                user.delete()
            except User.DoesNotExist:
                pass
            user = User.objects.create_user(username, email)
            user.save()
            info = TwitterInfo(user=user, screen_name=screen_name, id=twitter_id, token=token, secret=secret)
            if user_info:
                copy_info(user_info, info)
            info.save()
        return user
Exemplo n.º 4
0
 def authenticate(self, twitter_id=None, username=None, token=None, secret=None):
     logger.debug("Authenticating with: %s, %s, %s, %s" % (twitter_id, username, token, secret))
     # find or create the user
     try:
         info = TwitterInfo.objects.get(id=twitter_id)
         logger.debug("Found twitter user: %s" % info.name)
         # make sure the screen name is current
         _dirty = False
         if info.name != username:
             info.name = username
             _dirty = True
             
         #Sometimes the credentials change - ie, are revoked and the user reauthorizes, the app is updated, etc... 
         #We need to repersist if they change
         if info.token != token:
             info.token = token
             _dirty = True
         if info.secret != secret:
             info.secret = secret
             _dirty = True
         
         if _dirty:    
             info.save()
         user = info.user
     except TwitterInfo.DoesNotExist:
         logger.debug("User not found: %s" % username)
         email    = "*****@*****.**" % username
         try:
             logger.debug("Creating user: %s with email: %s " % (username, email))
             user     = User.objects.create_user(settings.USERS_FORMAT % username, email)
             user.save()
             logger.debug("Saving twitter credentials: %s with twitter id: %s " % (username, twitter_id))
             info = TwitterInfo(user=user, name=username, id=twitter_id, token=token, secret=secret)
             info.save()
         except:
             (e, v, tb) = sys.exc_info()
             logger.warn(e)
             logger.warn(v)
             traceback.print_tb(tb)
     return user