Revision 1439d638 snf-astakos-app/astakos/im/middleware.py

b/snf-astakos-app/astakos/im/middleware.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from urlparse import urlunsplit, urlsplit
35

  
36 34
from django.http import HttpResponse
37
from django.utils.http import urlencode
38 35

  
39 36
from astakos.im.cookie import Cookie
40
from astakos.im.util import get_query
41 37

  
42 38

  
43 39
class CookieAuthenticationMiddleware(object):
......
45 41
        cookie = Cookie(request)
46 42
        if cookie.is_valid:
47 43
            return
48
        
44

  
49 45
        response = HttpResponse(status=302)
50
        
51
        parts = list(urlsplit(request.path))
52
        params = get_query(request)
53
        parts[3] = urlencode(params)
54
        url = urlunsplit(parts)
55
        
56
        response['Location'] = url
46
        response['Location'] = request.get_full_path()
57 47
        cookie.fix(response)
58 48
        return response
59
    
49

  
60 50
    def process_response(self, request, response):
61
        Cookie(request, response).fix()
62
        return response
51
        cookie = Cookie(request, response)
52
        # if the user authentication status has changed during the processing
53
        # set/delete the cookie appropriately
54
        if not cookie.is_valid:
55
            cookie.fix()
56
        return response

Also available in: Unified diff