I am assuming that by "static resource/directory" you mean a portion of
a url, like - http://www.example.com/$username/ - If that is the case
then what you are looking for should be relatively easy, with one small
exception.
First off, you will have to secure the controller. Since you are
probably going to be putting multiple pages/controller methods behind
this resource it is probably easier to create a controller class that
derives from identity.SecureResource than to restrict each method
individually. Handing methods individually is more flexible though, so
you might want to consider that if you want portions of your controller
class to be publicly accessible. Enough talk though, on with the show.
Securing an entire controller class is actually pretty simple. The
"require" check that you would normally use as a decorator is moved to
a class variable. Here is a regular, unrestricted class.
class sample:
@expose(template=".templates.welcome")
def index(self):
return dict(message="Hi")
Obviously nothing fancy, but it works. Here is that same class, now
restricted so that only "administrators" can view it.
from turbogears import identity, controllers
class sample(controllers.Controller, identity.SecureResource):
require=identity.in_group('administrators')
@expose(template=".templates.welcome")
def index(self):
return dict(message="Hi")
As you can see, the change is pretty simple. The 'require' attribute
takes all of the same checks that you would normally use in a
decorator. There is only a slight problem though, we wanted to use
"http://www.example.com/$username" as the url, not /sample. To solve
this you should probably look into CherryPy filters, which are designed
for this sort of thing. Unfortunately I haven't had a change (read as:
reason) to play with them yet, so I don't know what to suggest. CP runs
a mailing list on google groups, so you might want to search through
that to start, I'm sure someone has asked before.
-Adam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---