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

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Thu Jun 5 16:10:36 UTC 2014


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'] = '/'
+            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:
-- 
1.9.3




More information about the Kimchi-devel mailing list