Login

Little middleware that create a facebook user

Author:
marinho
Posted:
December 16, 2007
Language:
Python
Version:
.96
Score:
0 (after 0 ratings)

How to use:

  1. Install PyFacebook package.
  2. After make all steps in tutorial above, put this code in your app's models.py module (you maybe prefer split it and put the middleware class in some other file).
  3. Put the FacebookUserMiddleware python-path in the MIDDLEWARE_CLASSES in your settings.py (after facebook.djangofb.FacebookMiddleware).

You probably will add some fields to FacebookUser model class :)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from facebook import Facebook
from django.db import models
from django.contrib.auth.models import User

class FacebookUser(models.Model):
    user = models.ForeignKey(User, null=True, blank=True)
    uid = models.IntegerField()

    def __unicode__(self):
        return str(uid)

    class Meta:
        pass

    class Admin:
        pass

class FacebookUserMiddleware(object):
    def process_request(self, request):
        if not request.POST.get('fb_sig', None):
            return

        request.facebook.user, new = FacebookUser.objects.get_or_create(uid=int(request.POST.get('fb_sig_user')))

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 9 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 4 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
  5. Help text hyperlinks by sa2812 1 year, 5 months ago

Comments

Please login first before commenting.