Changeset - b98f4431671c
[Not reviewed]
stable
0 2 0
Mads Kiilerich - 10 years ago 2015-09-20 22:22:50
madski@unity3d.com
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.
2 files changed with 8 insertions and 11 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/login.py
Show inline comments
 
@@ -74,22 +74,19 @@ class LoginController(BaseController):
 
            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 @@ class LoginController(BaseController):
 
            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')
 

	
kallithea/templates/login.html
Show inline comments
 
@@ -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 -->
0 comments (0 inline, 0 general)