Revision e510fae4
b/snf-astakos-app/astakos/im/target/redirect.py | ||
---|---|---|
43 | 43 |
from urlparse import urlunsplit, urlsplit, urlparse, parse_qsl |
44 | 44 |
|
45 | 45 |
from astakos.im.settings import COOKIE_NAME, COOKIE_DOMAIN |
46 |
from astakos.im.util import set_cookie |
|
46 |
from astakos.im.util import set_cookie, has_signed_terms
|
|
47 | 47 |
|
48 | 48 |
import logging |
49 | 49 |
|
... | ... | |
53 | 53 |
""" |
54 | 54 |
If there is no `next` request parameter redirects to astakos index page displaying an error |
55 | 55 |
message. |
56 |
If the request user is authenticated, redirects to `next` request parameter.
|
|
56 |
If the request user is authenticated and has signed the approval terms, redirects to `next` request parameter. If not, redirects to approval terms in order to return back here after agreeing with the terms.
|
|
57 | 57 |
Otherwise, redirects to login in order to return back here after successful login. |
58 | 58 |
""" |
59 | 59 |
next = request.GET.get('next') |
... | ... | |
65 | 65 |
logout(request) |
66 | 66 |
response.delete_cookie(COOKIE_NAME, path='/', domain=COOKIE_DOMAIN) |
67 | 67 |
if request.user.is_authenticated(): |
68 |
# if user has not signed the approval terms |
|
69 |
# redirect to approval terms with next the request path |
|
70 |
if not has_signed_terms(request.user): |
|
71 |
# first build next parameter |
|
72 |
parts = list(urlsplit(request.build_absolute_uri())) |
|
73 |
params = dict(parse_qsl(parts[3], keep_blank_values=True)) |
|
74 |
# delete force parameter |
|
75 |
parts[3] = urlencode(params) |
|
76 |
next = urlunsplit(parts) |
|
77 |
|
|
78 |
# build url location |
|
79 |
parts[2] = reverse('latest_terms') |
|
80 |
params = {'next':next} |
|
81 |
parts[3] = urlencode(params) |
|
82 |
url = urlunsplit(parts) |
|
83 |
response['Location'] = url |
|
84 |
response.status_code = 302 |
|
85 |
return response |
|
68 | 86 |
renew = request.GET.get('renew', None) |
69 | 87 |
if renew == '': |
70 | 88 |
request.user.renew_token() |
... | ... | |
82 | 100 |
response.status_code = 302 |
83 | 101 |
return response |
84 | 102 |
else: |
85 |
# redirect to login with self as next
|
|
103 |
# redirect to login with next the request path
|
|
86 | 104 |
|
87 | 105 |
# first build next parameter |
88 | 106 |
parts = list(urlsplit(request.build_absolute_uri())) |
Also available in: Unified diff