summaryrefslogtreecommitdiffstats
path: root/forum_modules/facebookauth
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-03-27 16:06:23 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-03-27 16:07:39 -0400
commitacd9aeca8e697b6d1f8f7ac29d7e3afac07b2e8a (patch)
treedbb232a017f71934cfb05b264db0cca40ac00164 /forum_modules/facebookauth
parent40ea3f482ffdfd648366ed20a87335dc31e92231 (diff)
downloadaskbot-acd9aeca8e697b6d1f8f7ac29d7e3afac07b2e8a.tar.gz
askbot-acd9aeca8e697b6d1f8f7ac29d7e3afac07b2e8a.tar.bz2
askbot-acd9aeca8e697b6d1f8f7ac29d7e3afac07b2e8a.zip
removed authentication module to be replaced with a dedicated app, also switched to table layout for openid signin template temporarily so that it works on IE7 and maybe earlier
Diffstat (limited to 'forum_modules/facebookauth')
-rwxr-xr-xforum_modules/facebookauth/__init__.py0
-rwxr-xr-xforum_modules/facebookauth/authentication.py85
-rwxr-xr-xforum_modules/facebookauth/settings.py3
-rwxr-xr-xforum_modules/facebookauth/templates/button.html38
-rwxr-xr-xforum_modules/facebookauth/templates/xd_receiver.html1
-rwxr-xr-xforum_modules/facebookauth/urls.py9
-rwxr-xr-xforum_modules/facebookauth/views.py11
7 files changed, 0 insertions, 147 deletions
diff --git a/forum_modules/facebookauth/__init__.py b/forum_modules/facebookauth/__init__.py
deleted file mode 100755
index e69de29b..00000000
--- a/forum_modules/facebookauth/__init__.py
+++ /dev/null
diff --git a/forum_modules/facebookauth/authentication.py b/forum_modules/facebookauth/authentication.py
deleted file mode 100755
index 512367a3..00000000
--- a/forum_modules/facebookauth/authentication.py
+++ /dev/null
@@ -1,85 +0,0 @@
-import hashlib
-from time import time
-from datetime import datetime
-from urllib import urlopen, urlencode
-from forum.authentication.base import AuthenticationConsumer, ConsumerTemplateContext, InvalidAuthentication
-from django.utils.translation import ugettext as _
-
-import settings
-
-try:
- from json import load as load_json
-except:
- from django.utils.simplejson import JSONDecoder
-
- def load_json(json):
- decoder = JSONDecoder()
- return decoder.decode(json.read())
-
-class FacebookAuthConsumer(AuthenticationConsumer):
-
- def process_authentication_request(self, request):
- API_KEY = settings.FB_API_KEY
-
- if API_KEY in request.COOKIES:
- if self.check_cookies_signature(request.COOKIES):
- if self.check_session_expiry(request.COOKIES):
- return request.COOKIES[API_KEY + '_user']
- else:
- raise InvalidAuthentication(_('Sorry, your Facebook session has expired, please try again'))
- else:
- raise InvalidAuthentication(_('The authentication with Facebook connect failed due to an invalid signature'))
- else:
- raise InvalidAuthentication(_('The authentication with Facebook connect failed, cannot find authentication tokens'))
-
- def generate_signature(self, values):
- keys = []
-
- for key in sorted(values.keys()):
- keys.append(key)
-
- signature = ''.join(['%s=%s' % (key, values[key]) for key in keys]) + settings.FB_APP_SECRET
- return hashlib.md5(signature).hexdigest()
-
- def check_session_expiry(self, cookies):
- return datetime.fromtimestamp(float(cookies[settings.FB_API_KEY+'_expires'])) > datetime.now()
-
- def check_cookies_signature(self, cookies):
- API_KEY = settings.FB_API_KEY
-
- values = {}
-
- for key in cookies.keys():
- if (key.startswith(API_KEY + '_')):
- values[key.replace(API_KEY + '_', '')] = cookies[key]
-
- return self.generate_signature(values) == cookies[API_KEY]
-
- def get_user_data(self, key):
- request_data = {
- 'method': 'Users.getInfo',
- 'api_key': settings.FB_API_KEY,
- 'call_id': time(),
- 'v': '1.0',
- 'uids': key,
- 'fields': 'name,first_name,last_name,email',
- 'format': 'json',
- }
-
- request_data['sig'] = self.generate_signature(request_data)
- fb_response = load_json(urlopen(settings.REST_SERVER, urlencode(request_data)))[0]
-
- return {
- 'username': fb_response['first_name'] + ' ' + fb_response['last_name'],
- 'email': fb_response['email']
- }
-
-class FacebookAuthContext(ConsumerTemplateContext):
- mode = 'BIGICON'
- type = 'CUSTOM'
- weight = 100
- human_name = 'Facebook'
- code_template = 'modules/facebookauth/button.html'
- extra_css = ["http://www.facebook.com/css/connect/connect_button.css"]
-
- API_KEY = settings.FB_API_KEY \ No newline at end of file
diff --git a/forum_modules/facebookauth/settings.py b/forum_modules/facebookauth/settings.py
deleted file mode 100755
index 67bf80c1..00000000
--- a/forum_modules/facebookauth/settings.py
+++ /dev/null
@@ -1,3 +0,0 @@
-REST_SERVER = 'http://api.facebook.com/restserver.php'
-FB_API_KEY = 'f773fab7be12aea689948208f37ad336'
-FB_APP_SECRET = '894547c1b8db54d77f919b1695ae879c' \ No newline at end of file
diff --git a/forum_modules/facebookauth/templates/button.html b/forum_modules/facebookauth/templates/button.html
deleted file mode 100755
index ceae1fc2..00000000
--- a/forum_modules/facebookauth/templates/button.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>
-<script type="text/javascript">
- var FB_API_KEY = "{{ provider.API_KEY }}";
- var FB_CHANNEL_PATH = "{% url xd_receiver %}";
-
- FB.init(FB_API_KEY, FB_CHANNEL_PATH, {permsToRequestOnConnect : "email"});
-
- function FB_ConnectPostAuthorization() {
- if ($('#validate_email').attr('checked')) {
- FB_RequireFeatures(["Api"], function(){
- var api = FB.Facebook.apiClient;
- var fb_uid = api.get_session().uid;
-
- $.post('{% url facebook_user_is_registered %}', {'fb_uid': fb_uid}, function(response) {
- if (response != "yes") {
- api.users_hasAppPermission("email", function(result) {
- if (!result) {
- FB.Connect.showPermissionDialog("email", redirect_to_done_page);
- } else {
- redirect_to_done_page()
- }
- })
- } else {
- redirect_to_done_page()
- }
- });
- });
- } else {
- redirect_to_done_page();
- }
- }
-
- function redirect_to_done_page() {
- window.location = "{% url auth_provider_done provider=provider.id %}";
- }
-
-</script>
-<fb:login-button v="2" size="medium" onlogin="FB_ConnectPostAuthorization()">Facebook</fb:login-button> \ No newline at end of file
diff --git a/forum_modules/facebookauth/templates/xd_receiver.html b/forum_modules/facebookauth/templates/xd_receiver.html
deleted file mode 100755
index 9c1664d2..00000000
--- a/forum_modules/facebookauth/templates/xd_receiver.html
+++ /dev/null
@@ -1 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <body> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script> </body> </html>
diff --git a/forum_modules/facebookauth/urls.py b/forum_modules/facebookauth/urls.py
deleted file mode 100755
index cbe3b6c7..00000000
--- a/forum_modules/facebookauth/urls.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from django.conf.urls.defaults import *
-from django.views.generic.simple import direct_to_template
-
-from views import user_is_registered
-
-urlpatterns = patterns('',
- url(r'^xd_receiver.htm$', direct_to_template, {'template': 'modules/facebookauth/xd_receiver.html'}, name='xd_receiver'),
- url(r'^facebook/user_is_registered/', user_is_registered, name="facebook_user_is_registered"),
-) \ No newline at end of file
diff --git a/forum_modules/facebookauth/views.py b/forum_modules/facebookauth/views.py
deleted file mode 100755
index f77c6282..00000000
--- a/forum_modules/facebookauth/views.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from forum.models import AuthKeyUserAssociation
-from django.http import HttpResponse
-
-def user_is_registered(request):
- try:
- fb_uid = request.POST['fb_uid']
- #print fb_uid
- AuthKeyUserAssociation.objects.get(key=fb_uid)
- return HttpResponse('yes')
- except:
- return HttpResponse('no') \ No newline at end of file