diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-12 22:51:11 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-12 22:51:11 -0400 |
commit | 3a3a11d32c72ab79ce94679aae7a549230c7104f (patch) | |
tree | 3ac36a302b85d5497b3d335238044c8f481ac0fd /forum/deps/django_authopenid/middleware.py | |
parent | 8b6a10ead45bcd915f5da223de2b3fd3c30fc7b5 (diff) | |
download | askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.tar.gz askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.tar.bz2 askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.zip |
moved livesettings and django_authopenid into forum/deps
Diffstat (limited to 'forum/deps/django_authopenid/middleware.py')
-rw-r--r-- | forum/deps/django_authopenid/middleware.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/forum/deps/django_authopenid/middleware.py b/forum/deps/django_authopenid/middleware.py new file mode 100644 index 00000000..d3da56da --- /dev/null +++ b/forum/deps/django_authopenid/middleware.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from forum.deps.django_authopenid import mimeparse +from django.http import HttpResponseRedirect +from django.core.urlresolvers import reverse +from django.conf import settings +import logging + +__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) + logging.debug('openid in session is: %s' % str(request.openid)) + + 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': + logging.debug('redirecting to yadis_xrdf:%s' % reverse('yadis_xrdf')) + return HttpResponseRedirect(reverse('yadis_xrdf')) + return response |