comparison pylons_app/lib/auth.py @ 199:78e406a4c58e

moved checking for user in session to wrapper function of LoginRequired decorator since it was working quite strange.
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 22 May 2010 20:47:34 +0200
parents da59b7e07e3c
children b48ebda822a4
comparison
equal deleted inserted replaced
198:c097458480a5 199:78e406a4c58e
39 39
40 class AuthUser(object): 40 class AuthUser(object):
41 """ 41 """
42 A simple object that handles a mercurial username for authentication 42 A simple object that handles a mercurial username for authentication
43 """ 43 """
44 username = 'Empty' 44 username = 'None'
45 is_authenticated = False 45 is_authenticated = False
46 is_admin = False 46 is_admin = False
47 permissions = set() 47 permissions = set()
48 group = set() 48 group = set()
49 49
59 """ 59 """
60 def __init__(self): 60 def __init__(self):
61 pass 61 pass
62 62
63 def __call__(self, func): 63 def __call__(self, func):
64 user = session.get('hg_app_user', AuthUser())
65 log.info('Checking login required for %s', user.username)
66 64
67 @wraps(func) 65 @wraps(func)
68 def _wrapper(*fargs, **fkwargs): 66 def _wrapper(*fargs, **fkwargs):
67 user = session.get('hg_app_user', AuthUser())
68 log.info('Checking login required for user:%s', user.username)
69 if user.is_authenticated: 69 if user.is_authenticated:
70 log.info('user %s is authenticated', user.username) 70 log.info('user %s is authenticated', user.username)
71 func(*fargs) 71 func(*fargs)
72 else: 72 else:
73 logging.info('user %s not authenticated', user.username) 73 logging.info('user %s not authenticated', user.username)
74 logging.info('redirecting to login page')
74 return redirect(url('login_home')) 75 return redirect(url('login_home'))
75 76
76 return _wrapper 77 return _wrapper