[Kimchi-devel] [PATCH V3 3/5] when login successfully, redirect to the last page.

Sheldon shaohef at linux.vnet.ibm.com
Tue Jun 10 12:45:38 UTC 2014


On 06/10/2014 02:13 AM, Aline Manera wrote:
> On 06/05/2014 01:10 PM, shaohef at linux.vnet.ibm.com wrote:
>> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>>
>> let cookie remember the last page.
>>
>> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>> Signed-off-by: Yu Xin Huo <huoyuxin at linux.vnet.ibm.com>
>> ---
>> src/kimchi/root.py | 16 ++++++++++++----
>> 1 file changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/kimchi/root.py b/src/kimchi/root.py
>> index 181ab13..651c847 100644
>> --- a/src/kimchi/root.py
>> +++ b/src/kimchi/root.py
>> @@ -93,7 +93,11 @@ def tabs(self, page, **kwargs):
>> data['ui_dir'] = paths.ui_dir
>>
>> if page.endswith('.html'):
>> - return template.render('tabs/' + page, data)
>> + context = template.render('tabs/' + page, data)
>> + cherrypy.response.cookie[
>> + "lastPage"] = "/#tabs/" + page.rstrip(".html")
>> + cherrypy.response.cookie['lastPage']['path'] = '/'
>
> Isn't only "lastPage" enough for that?
> Why [lastPage][path] is needed?
path is used to set the domain of the this cookie.
without this path, the lastPage cookie will just take effect for on page.
>
>> + return context
>> raise cherrypy.HTTPError(404)
>>
>>
>> @@ -115,9 +119,13 @@ def login(self, *args, **kwargs):
>> password = kwargs.get('password')
>> # forms base authentication
>> if username is not None:
>> - # UI can pass the redirect url by "next" query parameter
>> - next_url = kwargs.get('next', "/")
>> - next_url = type(next_url) is list and next_url[0]
>> + next_url = cherrypy.request.cookie.get("lastPage")
>> + if next_url is None:
>> + # UI can pass the redirect url by "next" query parameter
>> + next_url = kwargs.get('next', "/")
>> + next_url = type(next_url) is list and next_url[0]
>> + else:
>> + next_url = next_url.value
>> auth.login(username, password)
>> raise cherrypy.HTTPRedirect(next_url, 303)
>> else:
>
>
>


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list