Revision 1439d638
b/snf-astakos-app/astakos/im/cookie.py | ||
---|---|---|
36 | 36 |
from urllib import quote, unquote |
37 | 37 |
|
38 | 38 |
from django.contrib.auth.models import AnonymousUser |
39 |
from django.http import HttpRequest |
|
40 | 39 |
from django.utils.translation import ugettext as _ |
41 | 40 |
|
42 | 41 |
from astakos.im.settings import ( |
... | ... | |
46 | 45 |
|
47 | 46 |
logger = logging.getLogger(__name__) |
48 | 47 |
|
48 |
|
|
49 | 49 |
class Cookie(): |
50 | 50 |
def __init__(self, request, response=None): |
51 | 51 |
cookies = getattr(request, 'COOKIES', {}) |
... | ... | |
81 | 81 |
if not self.response: |
82 | 82 |
raise ValueError(_(astakos_messages.NO_RESPONSE)) |
83 | 83 |
user = self.user |
84 |
expire_fmt = user.auth_token_expires.strftime('%a, %d-%b-%Y %H:%M:%S %Z') |
|
84 |
expire_fmt = user.auth_token_expires.strftime( |
|
85 |
'%a, %d-%b-%Y %H:%M:%S %Z') |
|
85 | 86 |
if TRANSLATE_UUIDS: |
86 | 87 |
cookie_value = quote(user.username + '|' + user.auth_token) |
87 | 88 |
else: |
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 |
b/snf-django-lib/snf_django/lib/api/__init__.py | ||
---|---|---|
97 | 97 |
request.user_uniq = user_info["uuid"] |
98 | 98 |
request.user = user_info |
99 | 99 |
|
100 |
# Mark request as api call |
|
101 |
request.api_call = True |
|
102 |
|
|
100 | 103 |
# Get the response object |
101 | 104 |
response = func(request, *args, **kwargs) |
102 | 105 |
|
Also available in: Unified diff