[albatross-users] Newbie albatross question :)

Dave Cole djc at object-craft.com.au
Mon Nov 11 10:57:31 EST 2002


>>>>> "Tom" == Tom Emerson <tree at basistech.com> writes:

Tom> Could someone give some guidance on the use of redirects versus
Tom> set_page? Is the point that each major function carried out by an
Tom> application is handled by its own application object?

Tom> Or, I guess the question that I'm asking, is what is a good way
Tom> to structure a large application that isn't as stateful as the
Tom> pop sample but still requires state (such as login information).

set_page() is used in applications where the entire application hides
behind a single URL.  The application then keeps the name of the
current page in the session.

redirect() is used in applications where the current page is
determined by the URL requested by the browser.

If you want users to be able to bookmark pages in the application you
are going to have to use an application which inherits from
RandomPageModuleMixin.  In order to ensure that a user has logged in
you would have to do something like this:

- - - pagemodule.py - - - - - - - - - - - - - - - - - - - - - -
# Have login logic in separate module
import security

def page_process(ctx):
    if security.page_process(ctx):
        # process normal requests

def page_display(ctx):
    if security.page_display(ctx):
        # display normal page
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - security.py - - - - - - - - - - - - - - - - - - - - - - -
def process_login_request(ctx):
    # Check ctx.locals.username, ctx.locals.passwd, return TRUE if OK

def page_process(ctx):
    if ctx.req_equals('login'):
        ctx.locals._is_logged_on = process_login_request(ctx)
    return ctx.locals._is_logged_on

def page_display(ctx):
    if ctx.locals._is_logged_on:
        return 1
    ctx.run_template('login.html')
    return 0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list