[Twisted-web] Credential questions - hide user name andpasswordon login + get ip address in realm

Donovan Preston dp at divmod.org
Tue Nov 16 09:55:18 MST 2004

On Nov 16, 2004, at 7:50 AM, Alexander May wrote:

> Also, while on I'm on the subject of guard, is there a way to set the 
> url a
> user reaches after log in?  For example if the log in form is at
> http:/foo.com/, I would like the admin log in to end up at
> http:/foo.com/Admin/, and the non admin log in to end up at
> http:/foo.com/Home/.  Currently, both just end up at the root url.  
> Should
> the respective resources returned in Realm:requestAvatar just do a 
> redirect,
> or is some simple way to rewrite the url?  I tried muddling with the 
> various
> path members of the request in locateChild with no success.

The path segments which appear after the __login__ segment in the login 
form you generate will be used as the target of the redirect after 
login. Unfortunately this doesn't solve your problem, because you want 
to redirect based on the type of login. Perhaps the resource you return 
as / can immediately do a redirect to the appropriate URL? For example:

class Redirector:
     __implements__ = inevow.IResource,

     def __init__(self, avatar):
         self.avatar = avatar

     def calculateAppropriateRedirectURL(self):
         if self.avatar.admin: return '/Admin/'
         return '/Home/'

     def locateChild(self, ctx, segments):
         return self, ()

     def renderHTTP(self, ctx):

Perhaps also this redirect would only happen once, and set some state 
on self indicating it happened, and then do a normal page render if the 
user visited / after the first time.


More information about the Twisted-web mailing list