Commit 148b0cde authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

fix dummy target

- skip login() if user already logged in
- pass user & token to next

Refs: #1877
parent 6b4f9fb2
......@@ -32,15 +32,19 @@
# or implied, of GRNET S.A.
from django.http import HttpResponseBadRequest
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from urllib import quote
from astakos.im.target.util import prepare_response
def login(request):
next = request.GET.get('next')
if not next:
return HttpResponseBadRequest('No next step provided')
if not request.user:
return HttpResponseBadRequest('User not found')
return prepare_response(request, request.user, next)
if request.user.is_authenticated():
return prepare_response(request, request.user, next, skip_login=True)
else:
url = reverse('astakos.im.views.index')
url = '%s?next=%s' % (url, quote(request.build_absolute_uri()))
return redirect(url)
......@@ -42,7 +42,7 @@ from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.auth import login
def prepare_response(request, user, next='', renew=False):
def prepare_response(request, user, next='', renew=False, skip_login=False):
"""Return the unique username and the token
as 'X-Auth-User' and 'X-Auth-Token' headers,
or redirect to the URL provided in 'next'
......@@ -61,8 +61,7 @@ def prepare_response(request, user, next='', renew=False):
if next:
# TODO: Avoid redirect loops.
parts = list(urlsplit(next))
# Do not pass on user and token if we are on the same server.
if parts[1] and request.get_host() != parts[1]:
if not parts[1] or (parts[1] and request.get_host() != parts[1]):
parts[3] = urlencode({'user': user.username, 'token': auth_token})
next = urlunsplit(parts)
......@@ -73,7 +72,8 @@ def prepare_response(request, user, next='', renew=False):
next = reverse('astakos.im.views.edit_profile') + params
# user login
login(request, user)
if not skip_login:
login(request, user)
response = HttpResponse()
if not next:
......
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