# HG changeset patch # User Marcin Kuzminski # Date 1283033488 -7200 # Node ID 930f8182a884b8e7d98fe9ab7d7814d6f136e5a5 # Parent 28f19fa562dfe57dc6e2d655a76b05b38c45f363 Added redirection to page that request came from, after login in diff -r 28f19fa562df -r 930f8182a884 pylons_app/controllers/login.py --- a/pylons_app/controllers/login.py Sat Aug 28 14:53:32 2010 +0200 +++ b/pylons_app/controllers/login.py Sun Aug 29 00:11:28 2010 +0200 @@ -42,6 +42,8 @@ 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 @@ 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 -r 28f19fa562df -r 930f8182a884 pylons_app/lib/auth.py --- a/pylons_app/lib/auth.py Sat Aug 28 14:53:32 2010 +0200 +++ b/pylons_app/lib/auth.py Sun Aug 29 00:11:28 2010 +0200 @@ -228,8 +228,12 @@ 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 -r 28f19fa562df -r 930f8182a884 pylons_app/templates/login.html --- a/pylons_app/templates/login.html Sat Aug 28 14:53:32 2010 +0200 +++ b/pylons_app/templates/login.html Sun Aug 29 00:11:28 2010 +0200 @@ -24,7 +24,7 @@
- ${h.form(h.url.current())} + ${h.form(h.url.current(came_from=c.came_from))}