Package madrona :: Package openid :: Module middleware
[hide private]

Source Code for Module madrona.openid.middleware

 1  # -*- coding: utf-8 -*- 
 2  # Copyright 2007, 2008,2009 by Benoît Chesneau <benoitc@e-engura.org> 
 3  #  
 4  # Licensed under the Apache License, Version 2.0 (the "License"); 
 5  # you may not use this file except in compliance with the License. 
 6  # You may obtain a copy of the License at 
 7  # 
 8  #     http://www.apache.org/licenses/LICENSE-2.0 
 9  # 
10  # Unless required by applicable law or agreed to in writing, software 
11  # distributed under the License is distributed on an "AS IS" BASIS, 
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13  # See the License for the specific language governing permissions and 
14  # limitations under the License. 
15  # 
16   
17  from madrona.openid.utils.mimeparse import best_match 
18  from django.http import HttpResponseRedirect 
19  from django.core.urlresolvers import reverse 
20   
21  from madrona.openid.models import UserAssociation 
22  from madrona.openid.views import xrdf 
23  from madrona.common.utils import get_logger 
24   
25  __all__ = ["OpenIDMiddleware"] 
26  log = get_logger() 
27   
28 -class OpenIDMiddleware(object):
29 """ 30 Populate request.openid. This comes either from cookie or from 31 session, depending on the presence of OPENID_USE_SESSIONS. MP- HUH? I dont see that setting used anywhere 32 """
33 - def process_request(self, request):
34 request.openid = request.session.get('openid', None) 35 request.openids = request.session.get('openids', []) 36 37 # The code below seems benign and perfectly understandable (just grabs the openids and attaches a list to the request object) 38 # But for some unknown reason, this filter interacts with sessions in such a way that 39 # load_sessions fails to work on requests from the GE plugin 40 # 41 # Not sure what the implications are for excluding it but we shall see 42 # 43 #rels = UserAssociation.objects.filter(user__id=request.user.id) 44 rels = [] 45 request.associated_openids = [rel.openid_url for rel in rels]
46
47 - def process_response(self, request, response):
48 if response.status_code != 200 or len(response.content) < 200: 49 return response 50 path = request.get_full_path() 51 if path == "/" and 'HTTP_ACCEPT' in request.META and \ 52 best_match(['text/html', 'application/xrds+xml'], 53 request.META['HTTP_ACCEPT']) == 'application/xrds+xml': 54 response = xrdf(request) 55 return response
56