On Sat, Feb 28, 2009 at 5:51 AM, Rajesh <[email protected]> wrote:
>
> I am newbie to python & webpy and i really started liking it. I just
> want to know how do i apply filters. For example there are certain
> pages in my app which can be viewed after I login to the app, if not
> logged in, route the user to login page. I looked at the cookbook
> where Processors and Hooks were given. Can someone please explain
> these two concepts with examples.

Here is a sample code do what you wanted.

app = web.application(urls, globals())

def login_processor(handler):
    # web.ctx.path contains the current path requested
    if is_secret(web.ctx.path) and get_user() is None:
        raise web.seeother('/login?redirect=' + web.ctx.path)
    else:
        return handler()

you can fill in the details.

is_secret check if the give path requires login permissions.
get_user returns the name of currently logged in user  or None.
I'm assuming that login is at /login and it takes optional redirect
argument which is used to redirect the user back to that page after
login.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to