[Zope] Can I stop processing while saving data?
Shai Berger
shai@aristocart.com
Thu, 05 Apr 2001 01:48:38 +0200
Hi guys,
Problem: In our site, there are some pages that require
that a user be logged in. We implemented a login mechanism
using sessions, and we do not use Zope authentication.
Now, in order to make the maintenance of this manageable,
we used a property, called "LoginRequired", which is
checked by our standard_html_header. If a user tries
to access a document which has this property set, without
being logged in, we redirect her to the login page.
The thing is, it is very convenient to assume, while
developing, that if you set the "LoginRequired" property,
a user executing your code is logged in; thus, the
code in many places assumes things like a user_id in
the session data. This, in turn, means that if the
redirection is done with RESPONSE.redirect, a Zope
Error will occur in the processing of the page.
What we really want to do at this point is just stop
the processing -- and we can do that by a
<dtml-raise Redirect>.
The tricky part is, that an intelligent site, once
the user has logged in, takes her to the page she
asked to see in the first place. For this, we need
to keep some data -- like, where she was going, so
we can redirect her there after she logs in; and the
natural place for such info is in the session. But
raising an exception (like a Redirect) causes all
data changes to be rolled back, so we have a problem.
Up to now, we have been using SQLSession; there, we
could force a database commit before raising the
Redirect exception. This is an ugly kludge, but
it worked. Now we want to switch to CoreSessionTracking,
and I see no nice or kludgey way to do it there.
Any ideas?
Thanks,
Shai.