Revision 6a6ceeb0
b/snf-astakos-app/astakos/im/cookie.py | ||
---|---|---|
1 | 1 |
# Copyright 2011-2012 GRNET S.A. All rights reserved. |
2 |
#
|
|
2 |
# |
|
3 | 3 |
# Redistribution and use in source and binary forms, with or |
4 | 4 |
# without modification, are permitted provided that the following |
5 | 5 |
# conditions are met: |
6 |
#
|
|
6 |
# |
|
7 | 7 |
# 1. Redistributions of source code must retain the above |
8 | 8 |
# copyright notice, this list of conditions and the following |
9 | 9 |
# disclaimer. |
10 |
#
|
|
10 |
# |
|
11 | 11 |
# 2. Redistributions in binary form must reproduce the above |
12 | 12 |
# copyright notice, this list of conditions and the following |
13 | 13 |
# disclaimer in the documentation and/or other materials |
14 | 14 |
# provided with the distribution. |
15 |
#
|
|
15 |
# |
|
16 | 16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
17 | 17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | 18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
... | ... | |
25 | 25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
26 | 26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | 27 |
# POSSIBILITY OF SUCH DAMAGE. |
28 |
#
|
|
28 |
# |
|
29 | 29 |
# The views and conclusions contained in the software and |
30 | 30 |
# documentation are those of the authors and should not be |
31 | 31 |
# interpreted as representing official policies, either expressed |
... | ... | |
53 | 53 |
self.uuid, sep, self.auth_token = cookie.partition('|') |
54 | 54 |
self.request = request |
55 | 55 |
self.response = response |
56 |
|
|
56 |
|
|
57 | 57 |
@property |
58 | 58 |
def uuid(self): |
59 | 59 |
return getattr(self, 'uuid', '') |
60 |
|
|
60 |
|
|
61 | 61 |
@property |
62 | 62 |
def auth_token(self): |
63 | 63 |
return getattr(self, 'auth_token', '') |
64 |
|
|
64 |
|
|
65 | 65 |
@property |
66 | 66 |
def is_set(self): |
67 | 67 |
no_token = not self.auth_token |
68 | 68 |
return not no_token |
69 |
|
|
69 |
|
|
70 | 70 |
@property |
71 | 71 |
def is_valid(self): |
72 | 72 |
return self.uuid == getattr(self.user, 'uuid', '') and \ |
73 | 73 |
self.auth_token == getattr(self.user, 'auth_token', '') |
74 |
|
|
74 |
|
|
75 | 75 |
@property |
76 | 76 |
def user(self): |
77 | 77 |
return getattr(self.request, 'user', AnonymousUser()) |
78 |
|
|
78 |
|
|
79 | 79 |
def __set(self): |
80 | 80 |
if not self.response: |
81 | 81 |
raise ValueError(_(astakos_messages.NO_RESPONSE)) |
... | ... | |
88 | 88 |
) |
89 | 89 |
msg = 'Cookie [expiring %(auth_token_expires)s] set for %(uuid)s' % user.__dict__ |
90 | 90 |
logger._log(LOGGING_LEVEL, msg, []) |
91 |
|
|
91 |
|
|
92 | 92 |
def __delete(self): |
93 | 93 |
if not self.response: |
94 | 94 |
raise ValueError(_(astakos_messages.NO_RESPONSE)) |
95 | 95 |
self.response.delete_cookie(COOKIE_NAME, path='/', domain=COOKIE_DOMAIN) |
96 | 96 |
msg = 'Cookie deleted for %(uuid)s' % self.__dict__ |
97 | 97 |
logger._log(LOGGING_LEVEL, msg, []) |
98 |
|
|
98 |
|
|
99 | 99 |
def fix(self, response=None): |
100 | 100 |
self.response = response or self.response |
101 | 101 |
try: |
Also available in: Unified diff