[PATCH] login: preserve GET arguments throughout login redirection (issue #104)

Mads Kiilerich mads at kiilerich.com
Wed May 20 06:16:11 EDT 2015


On 05/20/2015 09:22 AM, Thomas De Schampheleire wrote:
> # HG changeset patch
> # User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
> # Date 1432065035 -7200
> #      Tue May 19 21:50:35 2015 +0200
> # Node ID cedc3ee5ef792a77a515997c90b38099f4688166
> # Parent  579110ca5178f13254e7e4c7b6043767a11b92a2
> login: preserve GET arguments throughout login redirection (issue #104)
>
> When redirecting a user to the login page and while handling this login and
> redirecting to the original page, the GET arguments passed to the original
> URL are lost through the login redirection process.
>
> For example, when creating a pull request for a specific revision from the
> repository changelog, there are rev_start and rev_end arguments passed in
> the URL. Through the login redirection, they are lost.
>
> Fix the issue by passing along the GET arguments to the login page, in the
> login form action, and when redirecting back to the original page.
> Tests are added to cover these cases.
>
> diff --git a/kallithea/controllers/login.py b/kallithea/controllers/login.py
> --- a/kallithea/controllers/login.py
> +++ b/kallithea/controllers/login.py
> @@ -100,7 +100,12 @@ class LoginController(BaseController):
>               log.error('Suspicious NETLOC detected %s for url %s server url '
>                         'is: %s' % (parsed.netloc, parsed, server_parsed))
>               came_from = url('home')
> -        return came_from
> +        return came_from.encode('ascii')

Why this? Should the type of the result from this function really be 
changed? What if the content cannot be encoded to ascii?

(Might be worth adding a test for this.)

> +
> +    def _redirect_to_origin(self, origin, headers=None):
> +        '''redirect to the original page, preserving any get arguments given'''
> +        request.GET.pop('came_from', None)
> +        raise HTTPFound(location=url(origin, **request.GET), headers=headers)
>

/Mads


More information about the kallithea-general mailing list