--- webhappyrealm.py Tue Jul 15 10:28:14 2003 +++ webhappyrealm.py Tue Jul 15 01:23:28 2003 @@ -3,15 +3,18 @@ from twisted.cred.portal import IRealm from twisted.web.static import Data from twisted.web.resource import Resource, IResource +from twisted.web.util import Redirect class MyRealm: __implements__ = IRealm def requestAvatar(self, avatarId, mind, *interfaces): if IResource in interfaces: if avatarId: - return IResource, Data("logged in as %s" % avatarId, "text/plain"), lambda : None + res = Resource() + res.putChild("", Data("logged in as %s" % avatarId, "text/plain")) + return IResource, res, lambda : None else: return IResource, Data("anonymous browsing - login", "text/html"), lambda : None else: raise NotImplementedError("no interface") @@ -41,10 +44,13 @@ sit = Site(res) res.putChild("", Data("site1
site2", "text/html")) +def redir(foo): + return Redirect('/site2') + # put our sites online from twisted.web.woven.guard import UsernamePasswordWrapper, SessionWrapper res.putChild("site1", SessionWrapper(UsernamePasswordWrapper(usersOnly))) -res.putChild("site2", SessionWrapper(UsernamePasswordWrapper(usersAndAnon))) +res.putChild("site2", SessionWrapper(UsernamePasswordWrapper(usersAndAnon, callback=redir))) # and finally talk to the internat from twisted.internet import reactor