# HG changeset patch # User Marcin Kuzminski # Date 2010-08-28 22:11:28 # Node ID 930f8182a884b8e7d98fe9ab7d7814d6f136e5a5 # Parent 28f19fa562dfe57dc6e2d655a76b05b38c45f363 Added redirection to page that request came from, after login in diff --git a/pylons_app/controllers/login.py b/pylons_app/controllers/login.py --- a/pylons_app/controllers/login.py +++ b/pylons_app/controllers/login.py @@ -42,6 +42,8 @@ class LoginController(BaseController): def index(self): #redirect if already logged in + c.came_from = request.GET.get('came_from',None) + if c.hg_app_user.is_authenticated: return redirect(url('hg_home')) @@ -50,7 +52,10 @@ class LoginController(BaseController): login_form = LoginForm() try: c.form_result = login_form.to_python(dict(request.POST)) - return redirect(url('hg_home')) + if c.came_from: + return redirect(c.came_from) + else: + return redirect(url('hg_home')) except formencode.Invalid as errors: return htmlfill.render( diff --git a/pylons_app/lib/auth.py b/pylons_app/lib/auth.py --- a/pylons_app/lib/auth.py +++ b/pylons_app/lib/auth.py @@ -228,8 +228,12 @@ class LoginRequired(object): return func(*fargs, **fkwargs) else: log.warn('user %s not authenticated', user.username) - log.debug('redirecting to login page') - return redirect(url('login_home')) + + p = request.environ.get('PATH_INFO') + if request.environ.get('QUERY_STRING'): + p+='?'+request.environ.get('QUERY_STRING') + log.debug('redirecting to login page with %',p) + return redirect(url('login_home',came_from=p)) class PermsDecorator(object): """Base class for decorators""" diff --git a/pylons_app/templates/login.html b/pylons_app/templates/login.html --- a/pylons_app/templates/login.html +++ b/pylons_app/templates/login.html @@ -24,7 +24,7 @@
- ${h.form(h.url.current())} + ${h.form(h.url.current(came_from=c.came_from))}