Changeset - 78e406a4c58e
[Not reviewed]
default
0 1 0
Marcin Kuzminski - 15 years ago 2010-05-22 20:47:34
marcin@python-works.com
moved checking for user in session to wrapper function of LoginRequired decorator since it was working quite strange.
1 file changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
pylons_app/lib/auth.py
Show inline comments
 
@@ -38,13 +38,13 @@ def authfunc(environ, username, password
 
    return False
 

	
 
class  AuthUser(object):
 
    """
 
    A simple object that handles a mercurial username for authentication
 
    """
 
    username = 'Empty'
 
    username = 'None'
 
    is_authenticated = False
 
    is_admin = False
 
    permissions = set()
 
    group = set()
 
    
 
    def __init__(self):
 
@@ -58,19 +58,20 @@ class LoginRequired(object):
 
    Must be logged in to execute this function else redirect to login page
 
    """
 
    def __init__(self):
 
        pass
 
    
 
    def __call__(self, func):
 
        user = session.get('hg_app_user', AuthUser())
 
        log.info('Checking login required for %s', user.username)
 
        
 
        @wraps(func)
 
        def _wrapper(*fargs, **fkwargs):
 
            user = session.get('hg_app_user', AuthUser())
 
            log.info('Checking login required for user:%s', user.username)            
 
            if user.is_authenticated:
 
                    log.info('user %s is authenticated', user.username)
 
                    func(*fargs)
 
            else:
 
                logging.info('user %s not authenticated', user.username)
 
                logging.info('redirecting to login page')
 
                return redirect(url('login_home'))
 

	
 
        return _wrapper
0 comments (0 inline, 0 general)