Commit 716963aa authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Merge branch 'master' of https://code.grnet.gr/git/astakos

parents 7482228b 8fbf5367
...@@ -124,7 +124,7 @@ def get_invitation(request): ...@@ -124,7 +124,7 @@ def get_invitation(request):
pass pass
return invitation return invitation
def prepare_response(request, user, next='', renew=False, skip_login=False): def prepare_response(request, user, next='', renew=False):
"""Return the unique username and the token """Return the unique username and the token
as 'X-Auth-User' and 'X-Auth-Token' headers, as 'X-Auth-User' and 'X-Auth-Token' headers,
or redirect to the URL provided in 'next' or redirect to the URL provided in 'next'
...@@ -141,13 +141,6 @@ def prepare_response(request, user, next='', renew=False, skip_login=False): ...@@ -141,13 +141,6 @@ def prepare_response(request, user, next='', renew=False, skip_login=False):
user.renew_token() user.renew_token()
user.save() user.save()
if next:
# TODO: Avoid redirect loops.
parts = list(urlsplit(next))
if not parts[1] or (parts[1] and request.get_host() != parts[1]):
parts[3] = urlencode({'user': user.email, 'token': user.auth_token})
next = urlunsplit(parts)
if settings.FORCE_PROFILE_UPDATE and not user.is_verified and not user.is_superuser: if settings.FORCE_PROFILE_UPDATE and not user.is_verified and not user.is_superuser:
params = '' params = ''
if next: if next:
...@@ -156,20 +149,19 @@ def prepare_response(request, user, next='', renew=False, skip_login=False): ...@@ -156,20 +149,19 @@ def prepare_response(request, user, next='', renew=False, skip_login=False):
response = HttpResponse() response = HttpResponse()
if not skip_login: # authenticate before login
# authenticate before login user = authenticate(email=user.email, auth_token=user.auth_token)
user = authenticate(email=user.email, auth_token=user.auth_token) login(request, user)
login(request, user) # set cookie
# set cookie expire_fmt = user.auth_token_expires.strftime('%a, %d-%b-%Y %H:%M:%S %Z')
expire_fmt = user.auth_token_expires.strftime('%a, %d-%b-%Y %H:%M:%S %Z') cookie_value = quote(user.email + '|' + user.auth_token)
cookie_value = quote(user.email + '|' + user.auth_token) response.set_cookie(settings.COOKIE_NAME, value=cookie_value,
response.set_cookie(settings.COOKIE_NAME, value=cookie_value, expires=expire_fmt, path='/',
expires=expire_fmt, path='/', domain = settings.COOKIE_DOMAIN)
domain = settings.COOKIE_DOMAIN)
if not next: if not next:
next = reverse('astakos.im.views.index') next = reverse('astakos.im.views.index')
response['Location'] = next response['Location'] = next
response.status_code = 302 response.status_code = 302
return response return response
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment