changeset 5508:b98f4431671c stable

login: inline _redirect_to_origin Refactor to simplify code and make next changes simpler. Let the controller handle came_from early and more explicit, thus simplifying the redirect flow.
author Mads Kiilerich <madski@unity3d.com>
date Sun, 20 Sep 2015 22:22:50 +0200
parents d4f66ca15110
children ad131f703996
files kallithea/controllers/login.py kallithea/templates/login.html
diffstat 2 files changed, 8 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/login.py	Thu Sep 17 21:29:46 2015 +0200
+++ b/kallithea/controllers/login.py	Sun Sep 20 22:22:50 2015 +0200
@@ -74,22 +74,19 @@
             return False
         return True
 
-    def _redirect_to_origin(self, origin):
-        '''redirect to the original page, preserving any get arguments given'''
-        request.GET.pop('came_from', None)
-        raise HTTPFound(location=url(origin, **request.GET))
-
     def index(self):
-        c.came_from = safe_str(request.GET.get('came_from', ''))
-        if not self._validate_came_from(c.came_from):
-            c.came_from = url('home')
+        c.came_from = safe_str(request.GET.pop('came_from', ''))
+        if self._validate_came_from(c.came_from):
+            came_from = url(c.came_from, **request.GET)
+        else:
+            c.came_from = came_from = url('home')
 
         not_default = self.authuser.username != User.DEFAULT_USER
         ip_allowed = AuthUser.check_ip_allowed(self.authuser, self.ip_addr)
 
         # redirect if already logged in
         if self.authuser.is_authenticated and not_default and ip_allowed:
-            return self._redirect_to_origin(c.came_from)
+            raise HTTPFound(location=came_from)
 
         if request.POST:
             # import Login Form validator class
@@ -119,7 +116,7 @@
             else:
                 log_in_user(user, c.form_result['remember'],
                     is_external_auth=False)
-                return self._redirect_to_origin(c.came_from)
+                raise HTTPFound(location=came_from)
 
         return render('/login.html')
 
--- a/kallithea/templates/login.html	Thu Sep 17 21:29:46 2015 +0200
+++ b/kallithea/templates/login.html	Sun Sep 20 22:22:50 2015 +0200
@@ -16,7 +16,7 @@
         %endif
     </div>
     <div class="panel-body inner">
-        ${h.form(h.url.current(**request.GET))}
+        ${h.form(h.url.current(came_from=c.came_from, **request.GET))}
         <div class="form">
             <i class="icon-lock"></i>
             <!-- fields -->