bad redirect url when trying access 'login required' page #1208

Closed
ramonz opened this Issue Mar 30, 2012 · 4 comments

Comments

Projects
None yet
4 participants

ramonz commented Mar 30, 2012

I found painful issue when LOGIN_URL contains query params.
For example in my settings.py a have:

    LOGIN_URL = '/accounts/?signin'

When I try accessing to private page I got redirect like /accounts/?signin?next=/path_to_private_page/

Small code changes in cms/views.py solves the problem:
was:

    93. tup = settings.LOGIN_URL , "next", path
    94. return HttpResponseRedirect('%s?%s=%s' % tup)

was now:

    93. parse_res = list(urlparse(settings.LOGIN_URL))
    94. params = parse_qsl(parse_res[4], True)  # 4 is query string
    95. params.append(('next', path))
    96. parse_res[4] = urlencode(params)
    97. url = unquote(urlunparse(parse_res))
    98. return HttpResponseRedirect(url)

after this changes redirect url is /accounts/?signin=&next=/path_to_private_page/

Contributor

kezabelle commented Mar 30, 2012

Django's auth views handle the same problem in a almost exactly the same way: see trunk of redirect_to_login, so the proposed fix should be fairly battle tested by now.

Edit: in fact, why not just call out to contrib.auth.views.redirect_to_login()? That view doesn't seem especially tied to the default auth implementation.

ramonz commented Mar 30, 2012

okay, better solution when using django 1.3.1:

    93. return redirect_to_login(path, settings.LOGIN_URL)

but not sure that other django versions have the exactly the same code in redirect_to_login func.

yakky added a commit to yakky/django-cms that referenced this issue Jul 11, 2013

Contributor

yakky commented Jul 11, 2013

Fixed in #2039

yakky added a commit to yakky/django-cms that referenced this issue Jul 11, 2013

Member

digi604 commented Jul 12, 2013

fixed

@digi604 digi604 closed this Jul 12, 2013

yakky added a commit to yakky/django-cms that referenced this issue Jul 12, 2013

yakky added a commit that referenced this issue Jul 17, 2013

yakky added a commit to yakky/django-cms that referenced this issue Jul 20, 2013

yakky added a commit to yakky/django-cms that referenced this issue Jul 20, 2013

yakky added a commit that referenced this issue Jul 20, 2013

yakky added a commit that referenced this issue Jul 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment