Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/marinho/pyfacebook
Browse files Browse the repository at this point in the history
  • Loading branch information
woodcoder committed May 18, 2010
2 parents 9dfe44f + abb0e03 commit c3bcec5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 13 deletions.
44 changes: 34 additions & 10 deletions facebook/__init__.py
Expand Up @@ -134,6 +134,12 @@ class json(object): pass
'getAllocation': [
('integration_point_name', str, []),
],
'getRestrictionInfo': [],
'setRestrictionInfo': [
('format', str, []),
('callback', str, ['optional']),
('restriction_str', json, ['optional']),
],
},

# auth methods
Expand Down Expand Up @@ -248,6 +254,14 @@ class json(object): pass
],
},

'dashboard': {
'addNews': [
('uid', int, []),
('news', json, []),
('image', str, ['optional']),
],
},

# notifications methods
'notifications': {
'get': [],
Expand Down Expand Up @@ -551,6 +565,20 @@ class json(object): pass
],
},

'links': {
'post': [
('url', str, []),
('comment', str, []),
('uid', int, []),
('image', str, ['optional']),
('callback', str, ['optional']),
],
'preview': [
('url', str, []),
('callback', str, ['optional']),
],
},

#comments methods
'comments' : {
'add' : [
Expand Down Expand Up @@ -1057,6 +1085,7 @@ def _parse_response_list(self, node):
def _check_error(self, response):
"""Checks if the given Facebook response is an error, and then raises the appropriate exception."""
if type(response) is dict and response.has_key('error_code'):
raise Exception(response) # XXX Marinho
raise FacebookError(response['error_code'], response['error_msg'], response['request_args'])


Expand Down Expand Up @@ -1290,7 +1319,7 @@ def check_session(self, request):
"""
self.in_canvas = (request.POST.get('fb_sig_in_canvas') == '1')

if self.session_key and (self.uid or self.page_id):
if not 'auth_token' in request.GET and self.session_key and (self.uid or self.page_id):
return True

if request.method == 'POST':
Expand All @@ -1303,6 +1332,7 @@ def check_session(self, request):
self.page_id = request.GET['fb_page_id']

if 'auth_token' in request.GET:
self.added = True # added by Marinho
self.auth_token = request.GET['auth_token']

try:
Expand Down Expand Up @@ -1343,14 +1373,9 @@ def check_session(self, request):
if params.get('added') == '1':
self.added = True

# fixed by Shuge Lee
# http://github.com/sciyoshi/pyfacebook/issues#issue/34
expires = params.get('expires', 0)
if expires == 'None':
expires = 0
else:
expires = int(expires)
self.session_key_expires = expires
if params.get('expires'):
# Marinho Brandao - fixing problem with no session
self.session_key_expires = params.get('expires', '').isdigit() and int(params['expires']) or 0

if 'locale' in params:
self.locale = params['locale']
Expand Down Expand Up @@ -1402,7 +1427,6 @@ def validate_signature(self, post, prefix='fb_sig', timeout=None):
args = post.copy()

if prefix not in args:
#HERE
return None

del args[prefix]
Expand Down
37 changes: 34 additions & 3 deletions facebook/djangofb/__init__.py
Expand Up @@ -5,7 +5,7 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
from datetime import datetime
#from datetime import datetime # by Marinho

try:
from threading import local
Expand Down Expand Up @@ -84,7 +84,12 @@ def newview(request, *args, **kwargs):
elif not isinstance(next, str):
next = ''

if not fb.check_session(request):
try:
session_check = fb.check_session(request)
except ValueError:
session_check = False

if not session_check:
#If user has never logged in before, the get_login_url will redirect to the TOS page
return fb.redirect(fb.get_login_url(next=next))

Expand Down Expand Up @@ -215,12 +220,38 @@ def process_request(self, request):
request.facebook.uid = request.session['facebook_user_id']

def process_response(self, request, response):
if not self.internal and request.facebook.session_key and request.facebook.uid:
#if not self.internal and request.facebook.session_key and request.facebook.uid:
# by Marinho
request.facebook.session_key = request.facebook.session_key == 'None' and None or request.facebook.session_key
request.facebook.uid = request.facebook.uid == 'None' and None or request.facebook.uid
if not self.internal and getattr(request, 'facebook', None) and request.facebook.session_key and request.facebook.uid:
request.session['facebook_session_key'] = request.facebook.session_key
request.session['facebook_user_id'] = request.facebook.uid

if request.facebook.session_key_expires:
expiry = datetime.datetime.fromtimestamp(request.facebook.session_key_expires)
request.session.set_expiry(expiry)

try:
fb = request.facebook
except:
return response

if not fb.is_session_from_cookie:
# Make sure the browser accepts our session cookies inside an Iframe
response['P3P'] = 'CP="NOI DSP COR NID ADMa OPTa OUR NOR"'
fb_cookies = {
'expires': fb.session_key_expires,
'session_key': fb.session_key,
'user': fb.uid,
}

expire_time = None
if fb.session_key_expires:
expire_time = datetime.datetime.utcfromtimestamp(fb.session_key_expires) # by Marinho

for k in fb_cookies:
response.set_cookie(self.api_key + '_' + k, fb_cookies[k], expires=expire_time)
response.set_cookie(self.api_key , fb._hash_args(fb_cookies), expires=expire_time)

return response

0 comments on commit c3bcec5

Please sign in to comment.