Example #1
0
    def authenticate(self, fb_uid=None, fb_object=None, request=None):
        """ If we receive a facebook uid then the cookie has already been validated. """
        if fb_uid:
            user, created = User.objects.get_or_create(username=fb_uid)

            if request and created:
                request.session['new_facebook_user'] = True

            try:
                if user.fb_profile:
                    exists = True
            except:
                exists = False

            # Consider replacing this synchronous data request (out to Facebook
            # and back) with an asynchronous request, using Celery or similar tool
            if FACEBOOK_PREPOPULATE_USER_DATA and (created or not exists) and fb_object:
                fb_user = fb_object.graph.get_object(u'me')
                user.first_name = fb_user['first_name']
                user.last_name  = fb_user['last_name']

                if 'email' in FACEBOOK_EXTENDED_PERMISSIONS and 'email' in fb_user:
                    user.email = fb_user['email']
                    
                user.save()

                profile = FacebookProfile.fromFacebookObject(fb_user, user)

            if FACEBOOK_PREPOPULATE_USER_DATA and fb_object and \
               user.fb_profile.last_update < datetime.now() - timedelta(1):
                user.fb_profile.update(fb_object.graph.get_object(u'me'))

            return user
        return None
Example #2
0
    def authenticate(self, fb_uid=None, fb_object=None, request=None):
        """ If we receive a facebook uid then the cookie has already been validated. """
        if fb_uid:
            user, created = User.objects.get_or_create(username=fb_uid)

            if request and created:
                request.session['new_facebook_user'] = True

            try:
                if user.fb_profile:
                    exists = True
            except:
                exists = False

            # Consider replacing this synchronous data request (out to Facebook
            # and back) with an asynchronous request, using Celery or similar tool
            if FACEBOOK_PREPOPULATE_USER_DATA and (created or
                                                   not exists) and fb_object:
                fb_user = fb_object.graph.get_object(u'me')
                user.first_name = fb_user['first_name']
                user.last_name = fb_user['last_name']

                if 'email' in FACEBOOK_EXTENDED_PERMISSIONS and 'email' in fb_user:
                    user.email = fb_user['email']

                user.save()

                profile = FacebookProfile.fromFacebookObject(fb_user, user)

            if FACEBOOK_PREPOPULATE_USER_DATA and fb_object and \
               user.fb_profile.last_update < datetime.now() - timedelta(1):
                user.fb_profile.update(fb_object.graph.get_object(u'me'))

            return user
        return None