Revision 4573cae0 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 urllib import unquote |
|
35 |
from urlparse import urlunsplit, urlsplit |
|
36 |
|
|
37 |
from django.http import HttpResponse |
|
38 |
from django.utils.http import urlencode |
|
39 |
|
|
34 | 40 |
from astakos.im.cookie import Cookie |
41 |
from astakos.im.settings import COOKIE_NAME |
|
42 |
from astakos.im.util import get_query |
|
35 | 43 |
|
36 | 44 |
class CookieAuthenticationMiddleware(object): |
45 |
def process_request(self, request): |
|
46 |
if request.user.is_authenticated(): |
|
47 |
return |
|
48 |
|
|
49 |
cookie = unquote(request.COOKIES.get(COOKIE_NAME, '')) |
|
50 |
if not cookie: |
|
51 |
return |
|
52 |
|
|
53 |
response = HttpResponse(status=302) |
|
54 |
|
|
55 |
parts = list(urlsplit(request.path)) |
|
56 |
params = get_query(request) |
|
57 |
parts[3] = urlencode(params) |
|
58 |
url = urlunsplit(parts) |
|
59 |
|
|
60 |
response['Location'] = url |
|
61 |
Cookie(request, response).fix() |
|
62 |
return response |
|
63 |
|
|
37 | 64 |
def process_response(self, request, response): |
38 | 65 |
Cookie(request, response).fix() |
39 | 66 |
return response |
Also available in: Unified diff