Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit bcff584b78519f7b2197686a348d67f5ac9aa171 0 parents
@aidanlister aidanlister authored
2  .gitignore
@@ -0,0 +1,2 @@
+*.pyc
+.DS_Store
1  README
@@ -0,0 +1 @@
+This app aims to replace Django's Authentication with Facebook.
0  __init__.py
No changes.
20 decorators.py
@@ -0,0 +1,20 @@
+from django.contrib.auth import REDIRECT_FIELD_NAME
+from django.http import HttpResponseRedirect, HttpResponse
+from django.utils.decorators import available_attrs
+from django.utils.http import urlquote
+
+def facebook_required(login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
+ """ Check the user has a valid facebook connection. """
+ if not login_url:
+ from django.conf import settings
+ login_url = settings.LOGIN_URL
+
+ def decorator(view_func):
+ def _wrapped_view(request, *args, **kwargs):
+ if request.facebook.uid:
+ return view_func(request, *args, **kwargs)
+ path = urlquote(request.get_full_path())
+ tup = login_url, redirect_field_name, path
+ #return HttpResponseRedirect('%s?%s=%s' % tup)
+ return HttpResponse('You must be logged in with Facebook.')
+ return wraps(view_func, assigned=available_attrs(view_func))(_wrapped_view)
38 middleware.py
@@ -0,0 +1,38 @@
+from django.conf import settings
+
+class Facebook(object):
+ def __init__(self, user=None):
+ if user is None:
+ self.uid = None
+ else:
+ self.uid = user['uid']
+ self.user = user
+ self.graph = facebook.GraphAPI(user['access_token'])
+
+
+
+class FacebookDebugCookieMiddleware(object):
+ """ Sets an imaginary cookie to make it easy to work from a development environment. """
+ def process_request(self, request):
+ cookie_name = "fbs_" + settings.FACEBOOK_APP_ID
+ request.COOKIES[cookie_name] = settings.FACEBOOK_DEBUG_COOKIE
+ return None
+
+
+class FacebookDebugTokenMiddleware(object):
+ """ Forces a specific access token to be used. """
+ def process_request(self, request):
+ fb_user = {
+ 'uid':u'212900950',
+ 'access_token':'2227470867|2.FkEuuS_4N9cqPqqjd_FaMg__.3600.1289257200-212900950|xK2pUhlDtAlO1jp_P4TCx8TeLog',
+ }
+ request.facebook = Facebook(fb_user)
+ return None
+
+
+class FacebookMiddleware(object):
+ """ Transparently integrate Django accounts with Facebook. """
+
+
+class TokenDebuggingMiddleware(object):
+ def process_request(self, request):
12 templates/facebook_init.html
@@ -0,0 +1,12 @@
+<div id="fb-root"></div>
+<script>
+ window.fbAsyncInit = function() {
+ FB.init({appId: {{ app_id }}, status: true, cookie: true, xfbml: true});
+ };
+ (function() {
+ var e = document.createElement('script'); e.async = true;
+ e.src = document.location.protocol +
+ '//connect.facebook.net/en_US/all.js';
+ document.getElementById('fb-root').appendChild(e);
+ }());
+</script>
0  templatetags/__init__.py
No changes.
12 templatetags/facebook.py
@@ -0,0 +1,12 @@
+from django import template
+from django.conf import settings
+register = template.Library()
+
+@register.inclusion_tag('facebook_init.html')
+def facebook_init():
+ try:
+ app_id = settings.FACEBOOK_APP_ID
+ except AttributeError:
+ raise template.TemplateSyntaxError, "%r tag requires FACEBOOK_APP_ID to be configured." \
+ % token.contents.split()[0]
+ return {'app_id': app_id}
0  views.py
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.