On May 12, 2010, at 10:42 PM, Oskar wrote:
> Hey!
>
> I would like to require users to be logged in to access any page
> (except one login page) on my site. But checking the session object in
> every GET/POST function seems like the wrong way to do it.
>
> Is there anyway I can put some code somewhere that gets executed no
> matter what page the user visits? Ideally I would like to send them to
> this one login page if they are not logged in.
I use decorator for this purpose.
# ----
def require_login(func):
def proxyfunc(self, *args, **kw):
if session.get('logged') is True:
return func(self, *args, **kw)
else:
session.kill()
web.seeother('/login?msg=loginRequired')
return proxyfunc
class Dashboard:
@require_login
def GET(self):
...
# ----
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.