Damjan wrote:

What's the quixote-ic way of getting the HTTP_REFERER?

Or otherwise, how do I get back from a login or logut URL?


Damjan,

I don't use HTTP_REFERER because the user is never actually successfully
on the page, and you would lose the right referrer if the user bungles
his username and password and you need to present the login page again.
Here is what I do for http://www.forecastwatch.com.  If the user tries
to access a page he needs to log in to, I throw a
"NotLoggedInException", which is caught by _q_exception_handler.  In the
handler for NotLoggedInException, I call the login page, sending it
request.get_path(), like so:

def _q_exception_handler [html] (request, exception):
   root = request.environ['SCRIPT_NAME']
   if exception.__class__ is SessionError:
       ...
   elif exception.__class__ is NotLoggedInError:
       message = str("<h1>Please Login to ForecastWatch.com</h1><p>\
       The page you are trying to access requires a valid username and
password.<br>\
       Please enter your username and password below and you will be
redirected<br>\
       to the page you are trying to access.</p>\
       <p>If you are having trouble, please email <a
href='mailto:[EMAIL PROTECTED]'>support</a>.<br></p>")
       default_page_onepane(request, root, "ForecastWatch.com Login",
login_rightpane(root, request, message, request.get_path()))

The code to build the login page then adds a form variable called
"redirect", which holds the value of the page the user was trying to
access.  Once the user submits the username and password, with the
hidden "redirect" variable, I call request.redirect(redirect), which
redirects the user to the original page, like so:

def login [html] (request):
   root = request.environ['SCRIPT_NAME']
   message = None
   redirect = request.get_form_var("redirect")
   if request.get_form_var("login"):
       # User is trying to login
       username = request.get_form_var("username")
       password = request.get_form_var("password")
       user = User(username, password, request.environ['REMOTE_ADDR'])

       # Is this a valid user?
       if user.isValid():
           # Valid user, but has user expired?
           if user.expired() and user.isDemoAccount():
               raise ExpiredDemoAccountError
           elif user.expired():
               raise ExpiredAccountError
           else:
               request.session.user = user
               if not redirect: redirect = str("%s/menu" % root)
               return request.redirect(redirect)
                       ...

While I don't do this, for a logout it would be simpler.  I assume you
want to display a "thanks" message for say 10 seconds, then redirect
back to the main page or something?  For that, just add this HTML to
your "thanks" page, which will redirect the user to the page of your choice:

<META HTTP-EQUIV="Refresh" CONTENT="10; URL=redirect-url...">

Where "10" is the number of seconds the user is to remain on this page,
and redirect-url... is the url of the page you want the user to be
redirected to.

Hope this helps!

Regards,
Eric Floehr
http://www.intellovations.com


_______________________________________________
Quixote-users mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/quixote-users

Reply via email to