[Twisted-web] RE: [Twisted-Python] Log in - state of the art?

Mike C. Fletcher mcfletch at rogers.com
Fri Nov 5 19:26:25 EST 2004


Alexander May wrote:
...

>1) If the user types in something like mysite.com/foo/bar and is not yet
>logged in, they get the "Sorry, but I couldn't find the object you
>requested." page.  I would like them to get the log in page, and then be
>redirected to the mysite.com/foo/bar afterwards.  Can I do this?
>  
>
Yes, you want to make the __login__ page precede the rest of the URL, so 
in my case, for the loginForm's locationChild method I do this:

    def locateChild(self, ctx, segments):
        """Locate child, return as inevow.IResource"""
        if segments:
            if segments[0] == 'style':
                return self.style, segments[1:]
            elif segments[0] == 'images':
                return self.images, segments[1:]
        inevow.IRequest(ctx).args[ 'finalURL'] = "/".join(segments)
        return self, ()

then in the form itself I access finalURL and make the address of the 
form reflect the final destination:
    <form tal:attributes="action python: 
'/%s/%s'%('__login__',REQUEST.form.get('finalURL',''))" method="get">

This doesn't, however, deal with re-encoding form values, so 
abcd.html?this=that still won't work.

Better approaches are likely available with a little more spelunking 
through the authorisation code...

>2) How do I replace the "Sorry, but I couldn't find the object you
>requested." with my own page?
>  
>
Haven't done this myself, from what I can see it would require some 
hacking inside Nevow:

from appserver.py

        if newres is None:
            from nevow.rend import FourOhFour
            return context.PageContext(tag=FourOhFour(), parent=pageContext)

where FourOhFour is just an IResource, but short of actually assigning 
to nevow.rend.FourOhFour I don't see a way to override it.

Good luck,
Mike

________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com





More information about the Twisted-Python mailing list