Hmm...Interesting idea. I was making an AuthPage class, but that just
forwarded to a Login class...Your idea of combining the two sounds promising,
and that method of keeping the query string in hidden variables is very
clever :)
Thanks,
Chris
On Tue, Oct 24, 2000 at 10:19:10AM -0400, Geoff Talvola wrote:
> > On Tue, 24 Oct 2000, Chris AtLee wrote:
> >
> > > Is there some delay built into redirects? What I'm trying to do is this:
> > > user goes to /index.py, index.py notices that user hasn't logged in, so redirects to login.py
> > > login.py accepts input, then redirects back to index.py.
> > >
> > > Each redirect generates what seems to be an extra request, and it takes
> > > about 2 seconds to complete the redirect. Am I doing something wrong?
>
> Another thing to consider -- it's possible to accomplish this without redirecting -- just build in
> the logic for doing login into a class derived from Page, call it SecurePage. Then all of your
> other pages are derived from SecurePage instead of Page. Your SecurePage class will have logic
> something like the following:
>
> class SecurePage(Page):
> def writeHTML(self):
> if username and password were POSTED:
> if username and password are correct:
> mark the user as logged in
> self.writePage()
> else:
> mark the user as logged out
> display an error page
> if user is logged in:
> self.writePage() # all derived classes should define this
> else:
> self.writeLoginForm()
> def writeLoginForm(self):
> # prints out a form that allows login, and POST's
> # the username and password to self.__class__.__name__.
>
> This is what I'm doing, and it works great. To make it work even better, I also have code in my
> writeLoginForm that generates hidden form variables for any request variables other than the login
> variables:
>
> for (key, value) in self.request().fields().items():
> if string.lower(key) not in ('username','password','login','logout'):
> self.write('<input type="hidden" name="%s" value="%s">'
> % (key, value))
>
> This way, your users can bookmark any url in your site, even ones with a query string attached.
> For instance, if your user bookmarks a url such as:
>
> http://localhost/WebKit.cgi/foo/bar?abc=123
>
> Then when they access it, if they're not logged in, it will show them the login page, then once
> they log in and submit their username and password, they will get the page they wanted, including
> the parameter abc=123. No redirects needed.
>
> If this seems a bit confusing, let me know. I might be persuaded to clean up my code and add it as
> a standard WebKit example page if Chuck deems it worthy.
>
> --
>
>
> - Geoff Talvola
> Parlance Corporation
> gtalvola@...
|