Example #1
0
 def test_logging_in_should_send_the_login_signal(self):
     counter = self.get_counter()
     
     user = self.create_user()
     self.create_profile(user)
     
     def handler(sender, **kwargs):
         counter.counter += 1
         self.assertEqual(self.profile, sender)
         
     login.connect(handler, sender=self.profile, dispatch_uid='socialreg.test.login')
     
     self.flow()
     
     self.assertEqual(1, counter.counter)
Example #2
0
    user = models.ForeignKey(User, unique=True)
    site = models.ForeignKey(Site, default=Site.objects.get_current)
    uid = models.CharField(max_length=255, blank=False, null=False)

    def __unicode__(self):
        try:
            return u'%s: %s' % (self.user, self.uid)
        except User.DoesNotExist:
            return u'None'

    def authenticate(self):
        return authenticate(uid=self.uid)
    
class FacebookAccessToken(models.Model):
    profile = models.OneToOneField(FacebookProfile, related_name='access_token')
    access_token = models.CharField(max_length=255)


def save_facebook_token(sender, user, profile, client, **kwargs):    
    try:
        FacebookAccessToken.objects.get(profile=profile).delete()
    except FacebookAccessToken.DoesNotExist:
        pass
    
    FacebookAccessToken.objects.create(profile=profile,
        access_token=client.graph.access_token)
    
connect.connect(save_facebook_token, sender=FacebookProfile,
    dispatch_uid='langkawi.facebook.connect')
login.connect(save_facebook_token, sender = FacebookProfile,
    dispatch_uid = 'langkawi.facebook.login')