summaryrefslogtreecommitdiffstats
path: root/django_authopenid/middleware.py
diff options
context:
space:
mode:
authorMike Chen <chagel@gmail.com>2009-07-05 10:23:06 +0800
committerMike Chen <chagel@gmail.com>2009-07-05 10:23:06 +0800
commit2acb62174ab2cac9c7a88faafcb5f0a22a54db6f (patch)
tree93e9d22d6fb8a6c882e3915a8511a3ac542a1e67 /django_authopenid/middleware.py
downloadaskbot-2acb62174ab2cac9c7a88faafcb5f0a22a54db6f.tar.gz
askbot-2acb62174ab2cac9c7a88faafcb5f0a22a54db6f.tar.bz2
askbot-2acb62174ab2cac9c7a88faafcb5f0a22a54db6f.zip
initiliaze git rep
Diffstat (limited to 'django_authopenid/middleware.py')
-rw-r--r--django_authopenid/middleware.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/django_authopenid/middleware.py b/django_authopenid/middleware.py
new file mode 100644
index 00000000..c0572c6e
--- /dev/null
+++ b/django_authopenid/middleware.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from django_authopenid import mimeparse
+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
+
+__all__ = ["OpenIDMiddleware"]
+
+class OpenIDMiddleware(object):
+ """
+ Populate request.openid. This comes either from cookie or from
+ session, depending on the presence of OPENID_USE_SESSIONS.
+ """
+ def process_request(self, request):
+ request.openid = request.session.get('openid', None)
+
+ def process_response(self, request, response):
+ if response.status_code != 200 or len(response.content) < 200:
+ return response
+ path = request.get_full_path()
+ if path == "/" and request.META.has_key('HTTP_ACCEPT') and \
+ mimeparse.best_match(['text/html', 'application/xrds+xml'],
+ request.META['HTTP_ACCEPT']) == 'application/xrds+xml':
+ return HttpResponseRedirect(reverse('yadis_xrdf'))
+ return response \ No newline at end of file