Changeset - 930f8182a884
[Not reviewed]
default
0 3 0
Marcin Kuzminski - 15 years ago 2010-08-29 00:11:28
marcin@python-works.com
Added redirection to page that request came from, after login in
3 files changed with 13 insertions and 4 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/login.py
Show inline comments
 
@@ -39,21 +39,26 @@ class LoginController(BaseController):
 

	
 
    def __before__(self):
 
        super(LoginController, self).__before__()
 

	
 
    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'))
 
        
 
        if request.POST:
 
            #import Login Form validator class
 
            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(
 
                    render('/login.html'),
 
                    defaults=errors.value,
 
                    errors=errors.error_dict or {},
pylons_app/lib/auth.py
Show inline comments
 
@@ -225,14 +225,18 @@ class LoginRequired(object):
 
        log.debug('Checking login required for user:%s', user.username)
 
        if user.is_authenticated:
 
            log.debug('user %s is authenticated', user.username)
 
            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"""
 
    
 
    def __init__(self, *required_perms):
 
        available_perms = config['available_permissions']
pylons_app/templates/login.html
Show inline comments
 
@@ -21,13 +21,13 @@
 
            <div class="title">
 
                <h5>${_('Sign In to hg-app')}</h5>
 
                <div class="corner tl"></div>
 
                <div class="corner tr"></div>
 
            </div>
 
            <div class="inner">            
 
                ${h.form(h.url.current())}
 
                ${h.form(h.url.current(came_from=c.came_from))}
 
                <div class="form">
 
                    <!-- fields -->
 

	
 
                    <div class="fields">
 
                        <div class="field">
 
                            <div class="label">
0 comments (0 inline, 0 general)