예제 #1
0
 def is_authenticated(self):
     """Check if this fb user is logged in"""
     _facebook_obj = get_facebook_client()
     if _facebook_obj.access_token and _facebook_obj.uid:
         my_profile = _facebook_obj.graph.get_object("me")
         fbid = my_profile["id"]
         if int(self.facebook_id) == int(fbid):
             return True
         else:
             return False
     else:
         return False
예제 #2
0
 def __get_facebook_info(self,fbids):
     """
        Takes an array of facebook ids and caches all the info that comes
        back. Returns a tuple - an array of all facebook info, and info for
        self's fb id.
     """
     _facebook_obj = get_facebook_client()
     all_info = []
     my_info = None
     ids_to_get = []
     for fbid in fbids:
         if fbid == 0 or fbid is None:
             continue
         
         if _facebook_obj.uid is None:
             cache_key = 'fb_user_info_%s' % fbid
         else:
             cache_key = 'fb_user_info_%s_%s' % (_facebook_obj.uid, fbid)
     
         fb_info_cache = cache.get(cache_key)
         if fb_info_cache:
             log.debug("Found %s in cache" % fbid)
             all_info.append(fb_info_cache)
             if fbid == self.facebook_id:
                 my_info = fb_info_cache
         else:
             log.debug("User info not found in cache at %s" % cache_key)
             ids_to_get.append(fbid)
     
     if len(ids_to_get) > 0:
         log.debug("Calling for %s" % ids_to_get)
         tmp_info = _facebook_obj.graph.get_objects([str(x) for x in ids_to_get])
         
         all_info.extend(tmp_info)
         for info_key in tmp_info.keys():
             info = tmp_info[info_key]
             if info_key == str(self.facebook_id):
                 my_info = info
             
             if _facebook_obj.uid is None:
                 cache_key = 'fb_user_info_%s' % fbid
             else:
                 cache_key = 'fb_user_info_%s_%s' % (_facebook_obj.uid, info['id'])
             
             log.debug('Caching user info with key %s' % cache_key)
             cache.set(
                 cache_key, 
                 info, 
                 getattr(settings, 'FACEBOOK_CACHE_TIMEOUT', 1800)
             )
             
     return all_info, my_info
예제 #3
0
 def __get_facebook_friends(self):
     """returns an array of the user's friends' fb ids"""
     _facebook_obj = get_facebook_client()
     friends = []
     cache_key = 'fb_friends_%s' % (self.facebook_id)
 
     fb_info_cache = cache.get(cache_key)
     if fb_info_cache:
         friends = fb_info_cache
     else:
         log.debug("Calling for '%s'" % cache_key)
         friends = _facebook_obj.friends.getAppUsers()
         cache.set(
             cache_key, 
             friends, 
             getattr(settings,'FACEBOOK_CACHE_TIMEOUT',1800)
         )
     
     return friends        
예제 #4
0
def unregister_fb_profile(sender, **kwargs):
    """call facebook and let them know to unregister the user"""
    fb = get_facebook_client()
    fb.connect.unregisterUser([fb.hash_email(kwargs['instance'].user.email)])
예제 #5
0
 def __get_picture_url(self):
    _facebook_obj = get_facebook_client()
    if self.__configure_me():
        return "https://graph.facebook.com/me/picture?access_token=%s" % _facebook_obj.access_token
    else:
        return self.DUMMY_FACEBOOK_INFO['pic_square_with_logo']