Help with authorization and redirection decorator in python (pylons)

Posted by ensnare on Stack Overflow See other posts from Stack Overflow or by ensnare
Published on 2010-04-27T18:49:59Z Indexed on 2010/04/27 18:53 UTC
Read the original article Hit count: 195

Filed under:
|
|
|
|

I'm trying to write a simple decorator to check the authentication of a user, and to redirect to the login page if s/he is not authenticated:

def authenticate(f):
    try:
        if user['authenticated'] is True:
            return f
    except:
        redirect_to(controller='login', action='index')

class IndexController(BaseController):
    @authenticate
    def index(self):
        return render('/index.mako' )

But this approach doesn't work. When a user is authenticated, everything is fine. But when the user is not authenticated, redirect_to() doesn't work and I am given this error:

HTTPFound: 302 Found Content-Type: text/html; charset=UTF-8 Content-Length: 0 location: /login

Thank for your help!

© Stack Overflow or respective owner

Related posts about python

Related posts about pylons