[Zope] session management

Anthony Pfrunder s341625@student.uq.edu.au
Mon, 16 Aug 1999 14:28:38 +1000 (GMT+1000)


On Sun, 15 Aug 1999, TR Henigson wrote:

> Has anyone built an object for managing session information
> in URL's or with cookies between client requests? Is anyone
> developing one? If such an object does not exist, how would
> I best implement session management for an e-commerce app?
> Thank you.

I believe that DigiCool will be releasing a Membership component as part
of the Zope Portel Toolkit (ZPT).  This should implement standard session
management however, I don't know when this will be released (check the ZPT
timeline posted a few weeks back, membership is last ;)

The general way I solve session management depends on what you want to do.
If you just require a Wizard style 1-2-3-4 steps type session simply
create a dictionary which is stored in your REQUEST variable,
packed/unpacked into hidden fields in a hidden form. ie

# Make a variable in the namespace
<dtml-var "REQUEST.set(mydict, [dict])">

<dtml-in REQUEST.FORMS.xx>
	# Update it for the hidden elements in your form
	<dtml-var "_['mydict'][entry] = _[sequence-item/index]">
</dtml-in>

# Do some stuff with mydict[items]

# Pack up the result for next link
<dtml-in _['mydict']>
	<dtml-var "_['url'] = _['url'] + urlencode(_['sequence-item'],
_['mydict'][sequence-item])">
</dtml-in>

# Store url as link 
<a href=<dtml-var url>>Next step</a>

The best way to do this generally is to override url.absolute or some such
function and wrap all links in it.  This way, all links automagically have
the session stuff 

The other way is to use cookies.  Here, you need include a cookie monster
in each page request.  Refer to DTML guide for info on this.
 
Cheers,

Anthony Pfrunder