Beispiel #1
0
def get_user(request):
    """
    Returns the user object associated with the request
    If doesn't exists, tries to create one 
    """
    try:
        user_object = User.objects.get(pk=1)#request.session['uid'])
    except:
        # Some error, try to return from facebook
        facebook_id = facebook.get_id(request)
        if facebook_id:
            # We have a facebook id
            try:
                # Try to retrieve the user object
                user_object = FacebookUser.objects.get(pk=facebook_id).user
            except:
                # If there is a error, create the objects
                user_object = User(email=facebook.get_email(request))
                user_object.save()
                facebook_object = FacebookUser(user=user_object)
                facebook_object.save()
            # Set the user id on session 
            request.session['uid'] = user_object.id
        else:
            # Do nothing
            user_object = None
    return user_object
Beispiel #2
0
def info(request):
    """info view it's just a simple test view for Facebook Integration"""
    try:
        request.COOKIES['sid']
        id = get_id(request)
        html = "id: %s" % (id,)
        return HttpResponse(html)
    except KeyError,ValueError:
        return HttpResponseRedirect(settings.ROOT_URL)