Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bcff584
Showing
9 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pyc | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This app aims to replace Django's Authentication with Facebook. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
Empty file.