[mod_python] Publisher Weirdness

marinus van aswegen mvanaswegen at gmail.com
Mon Feb 27 03:36:31 EST 2006


Hi I'm experiencing some mod_python weirdness. I write a log in function
that manages the user log in and session. The problem is that this function
just manages the session and doesn't need to send anything to the browser. I
read in the FAQ about the compulsive need by the handler to return
something.  I followed the recommendation in the FAQ but it's like the
browser just goes into limbo .... it's like it just gets stuck ... reading
data, I don't get any errors through, nothing in the logs either. I wrote a
small test function to see whats up.

Marinus

Code example below:

def validate_session(req):
    """
    this function must be called prior to all function to
    ensure that the user is autenticated
    """

    # get the session for this request
    session = Session.Session(req, secret = config.cookie_passwd)

    # is this req from a new session
    if session.is_new():
        util.redirect (req, config.base_url + 'login.html')

    if session.has_key('auth'):
        if session['auth'] != True:
            util.redirect (req, config.base_url + 'login.html')

    return 1

def login (req, uid = None, passwd = None):
    """
    connect to the database an authenticate the user
    """
    session = Session.Session(req, secret = config.cookie_passwd)

    # does this session have counter? Maby a new client
    if not session.has_key ('count'):
        session['count'] = 0
        session.save()

    #db_uid,db_passwd = mplib.db_query_one ('select uid,passwd from
security')
    db_uid = 'test'
    db_passwd = 'test'

    if db_uid == uid and db_passwd == passwd:
        session['uid'] = db_uid
        session['count'] = 0
        session['auth'] = True
        session.save()

        # the handler is obsessed with returning something, give it
something
        req.content_type = 'text/plain'
        return apache.OK
        #raise apache.SERVER_RETURN, apache.OK

    else:
        session['count'] += 1
        if session['count'] >= config.pass_fail:
            #session.invalidate()
            session.delete()
            util.redirect(req, config.base_url + 'logon_fail.html')
        session.save()
        util.redirect (req, config.base_url + 'login.html')


def test(req):

    validate_session(req)

    session = Session.Session(req, secret = config.cookie_passwd)

        req.content_type = 'text/plain'
    req.write('hello world\n')

    req.write( 'welcome %d\n' % (session['uid'] ))

    return apache.OK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060227/41a2d8ba/attachment.html


More information about the Mod_python mailing list