On Sun, 2004-03-07 at 15:04, Christopher Armstrong wrote:
James Y Knight wrote:
Janne mentioned on IRC that the actual goal is to be able to ask for username/password login for some children but not others. Thus, I suspect a solution where the SessionWrapper is on the root, but is configured somehow to not require login except for certain resources would work.
I dunno how to do that but it looks probably possible from the API?
It was certainly possible with woven.guard; you could pass in two separate resources, one for anon and one for loggedin. Of course those resources could also look at the session to see if the user is logged in, then redirect to the login screen if necessary. No idea how nevow.guard works.
Here's what I've been doing: --snip-- from twisted.cred import checkers from nevow import compy from nevow import inevow from nevow import rend class ICurrentUser(compy.Interface): pass class User: pass ANONYMOUS = User() class SimpleRealm: def requestAvatar(self, avatar_id, mind, *interfaces): if inevow.IResource in interfaces: if avatar_id is checkers.ANONYMOUS: user = ANONYMOUS else: user = createSomeUser(avatar_id) resc = createRootResource() resc.realm = self # The resource will remember this into its context, or # keep it around until it has one. resc.remember(user, ICurrentUser) return (inevow.IResource, resc, lambda:None) class MyResource(rend.Page): def getCurrentUser(self, ctx=None): if ctx is None: ctx = self.context if ctx is None: print "Hey, why can't I find a context?" return ANONYMOUS return ctx.locate(ICurrentUser) def isLoggedIn(self, ctx=None): return self.getCurrentUser(ctx) is not ANONYMOUS --snip-- ...then you can make render_* functions that display or hide parts of the web page based on the user. You can also make a LoggedInOnlyResource class that redirects to guard.LOGIN_AVATAR whenever it sees that the user isn't logged in. I'd be interested, though, in hearing what other ways people might have for accomplishing stuff like this. -- Alex Levy WWW: http://mesozoic.geecs.org "Never let your sense of morals prevent you from doing what is right." -- Salvor Hardin, Isaac Asimov's _Foundation_