webfaction and repo.or.cz deployment done
[worddb.git] / libs / django_authopenid / middleware.py
blobc0572c6e73a549847449d84505f7bf48e2e8dd8f
1 # -*- coding: utf-8 -*-
2 from django_authopenid import mimeparse
3 from django.http import HttpResponseRedirect
4 from django.core.urlresolvers import reverse
6 __all__ = ["OpenIDMiddleware"]
8 class OpenIDMiddleware(object):
9 """
10 Populate request.openid. This comes either from cookie or from
11 session, depending on the presence of OPENID_USE_SESSIONS.
12 """
13 def process_request(self, request):
14 request.openid = request.session.get('openid', None)
16 def process_response(self, request, response):
17 if response.status_code != 200 or len(response.content) < 200:
18 return response
19 path = request.get_full_path()
20 if path == "/" and request.META.has_key('HTTP_ACCEPT') and \
21 mimeparse.best_match(['text/html', 'application/xrds+xml'],
22 request.META['HTTP_ACCEPT']) == 'application/xrds+xml':
23 return HttpResponseRedirect(reverse('yadis_xrdf'))
24 return response