Changeset 8752 for mauRepo


Ignore:
Timestamp:
28/03/13 16:51:44 (7 years ago)
Author:
mnagni
Message:

Incomplete - # 22689: [CEDA Site Python Port] Logout link
 http://team.ceda.ac.uk/trac/ceda/ticket/22689

Location:
mauRepo/dj_security_middleware/trunk
Files:
1 deleted
4 copied
2 moved

Legend:

Unmodified
Added
Removed
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/middleware.py

    r8750 r8752  
    4343import re 
    4444import base64 
    45 from django.contrib.auth.views import logout 
    46 from cookielib import CookieJar 
    4745 
    4846# Get an instance of a logger 
     
    7573    """     
    7674    def process_request(self, request): 
     75        if len(request.REQUEST.get('logout', '')) > 0: 
     76            request.GET.setlist('logout', ()) 
     77            response = HttpResponseRedirect(_build_url(request))                                 
     78            response.delete_cookie(AUTH_TKT) 
     79            return response 
     80 
    7781        request.session['accountid'] = None 
    7882        url_fiters = getattr(settings, 'DJ_SECURITY_FILTER', None) 
     
    111115        except DJMiddlewareException as ex:         
    112116            LOGGER.info(ex) 
    113             url = '%s?%s' % (settings.DJ_SECURITY_LOGIN_SERVICE, _build_ret_url(request)) 
     117            url = '%s?%s' % (settings.DJ_SECURITY_LOGIN_SERVICE, _build_login_url(request)) 
    114118            LOGGER.info("error in authentication. Redirecting to %s" % (url)) 
    115119            return HttpResponseRedirect(url)            
    116120             
    117121    def process_response(self, request, response): 
    118         if len(request.REQUEST.get('logout', '')) > 0: 
    119             response.delete_cookie(AUTH_TKT) 
    120122        return response  
    121123 
    122 def _build_ret_url(request): 
     124def _build_url(request): 
    123125    hostname = socket.getfqdn() 
    124126    if request.META['SERVER_PORT'] != 80: 
    125127        hostname = "%s:%s" % (hostname, request.META['SERVER_PORT']) 
     128    return 'http://%s%s?%s' % (hostname, request.path, request.GET.urlencode()) 
     129 
     130def _build_login_url(request): 
    126131    qs = {} 
    127     qs['r'] = base64.b64encode('http://%s%s?%s' % (hostname, request.path, request.GET.urlencode())) 
     132    qs['r'] = base64.b64encode(_build_url(request)) 
    128133    return urlencode(qs)            
    129134 
     
    202207        if re.match(ifilter, string): 
    203208            return True 
    204          
    205 def logout(request): 
    206     """ 
    207         Removes the authenticated user's ID from the request and flushes their 
    208         session data, plus remove the auth_cookie 
    209     """ 
    210     logout(request) 
    211     CookieJar.clear(name = 'auth_tkt') 
Note: See TracChangeset for help on using the changeset viewer.