Revision 67920ea0
b/snf-astakos-app/astakos/api/user.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from time import time, mktime |
|
35 |
|
|
36 | 34 |
from django.http import HttpResponse |
37 | 35 |
from django.utils import simplejson as json |
38 | 36 |
from django.views.decorators.csrf import csrf_exempt |
... | ... | |
63 | 61 |
if not user: |
64 | 62 |
raise faults.BadRequest('No user') |
65 | 63 |
|
66 |
# Check if the is active. |
|
67 |
if not user.is_active: |
|
68 |
raise faults.Unauthorized('User inactive') |
|
69 |
|
|
70 |
# Check if the token has expired. |
|
71 |
if (time() - mktime(user.auth_token_expires.timetuple())) > 0: |
|
72 |
raise faults.Unauthorized('Authentication expired') |
|
73 |
|
|
74 |
if not user.signed_terms: |
|
75 |
raise faults.Unauthorized('Pending approval terms') |
|
76 |
|
|
77 | 64 |
response = HttpResponse() |
78 | 65 |
user_info = { |
79 | 66 |
'id': user.id, |
b/snf-astakos-app/astakos/api/util.py | ||
---|---|---|
80 | 80 |
raise faults.Unauthorized("Invalid X-Auth-Token") |
81 | 81 |
|
82 | 82 |
try: |
83 |
request.user = AstakosUser.objects.get(auth_token=token)
|
|
83 |
user = AstakosUser.objects.get(auth_token=token) |
|
84 | 84 |
except AstakosUser.DoesNotExist: |
85 | 85 |
raise faults.Unauthorized('Invalid X-Auth-Token') |
86 | 86 |
|
87 |
# Check if the user is active. |
|
88 |
if not user.is_active: |
|
89 |
raise faults.Unauthorized('User inactive') |
|
90 |
|
|
91 |
# Check if the token has expired. |
|
92 |
if user.token_expired(): |
|
93 |
raise faults.Unauthorized('Authentication expired') |
|
94 |
|
|
95 |
# Check if the user has accepted the terms. |
|
96 |
if not user.signed_terms: |
|
97 |
raise faults.Unauthorized('Pending approval terms') |
|
98 |
|
|
99 |
request.user = user |
|
87 | 100 |
return func(request, *args, **kwargs) |
88 | 101 |
return wrapper |
89 | 102 |
|
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
514 | 514 |
msg = 'Token renewed for %s' % self.log_display |
515 | 515 |
logger.log(astakos_settings.LOGGING_LEVEL, msg) |
516 | 516 |
|
517 |
def token_expired(self): |
|
518 |
return self.auth_token_expires < datetime.now() |
|
519 |
|
|
517 | 520 |
def flush_sessions(self, current_key=None): |
518 | 521 |
q = self.sessions |
519 | 522 |
if current_key: |
b/snf-astakos-app/astakos/im/util.py | ||
---|---|---|
158 | 158 |
or user has not a valid token. |
159 | 159 |
""" |
160 | 160 |
renew = renew or (not user.auth_token) |
161 |
renew = renew or (user.auth_token_expires < datetime.datetime.now())
|
|
161 |
renew = renew or user.token_expired()
|
|
162 | 162 |
if renew: |
163 | 163 |
user.renew_token( |
164 | 164 |
flush_sessions=True, |
Also available in: Unified diff