[PATCH 1 of 4 prefix exploded] login: inline _redirect_to_origin
Mads Kiilerich
mads at kiilerich.com
Fri Sep 18 17:27:09 UTC 2015
# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1442596983 -7200
# Fri Sep 18 19:23:03 2015 +0200
# Branch stable
# Node ID a61f96e3960e8752b7bf9e5812085d858369a210
# Parent d4f66ca1511011c9b50d347caff73ae65bcec1ca
login: inline _redirect_to_origin
Refactor to simplify code and make next changes simpler.
diff --git a/kallithea/controllers/login.py b/kallithea/controllers/login.py
--- a/kallithea/controllers/login.py
+++ b/kallithea/controllers/login.py
@@ -74,14 +74,11 @@ 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):
+ came_from = safe_str(request.GET.pop('came_from', ''))
+ if self._validate_came_from(came_from):
+ c.came_from = url(came_from, **request.GET)
+ else:
c.came_from = url('home')
not_default = self.authuser.username != User.DEFAULT_USER
@@ -89,7 +86,7 @@ class LoginController(BaseController):
# 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=c.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=c.came_from)
return render('/login.html')
More information about the kallithea-general
mailing list