Gustavo Narea schrieb:
> Eventually there will be a repoze.what network plugin, which will
> provide predicates for IP-based authorization, among other things.

Good; I really think repoze.what should have that included already.

 > In the mean time, you can use the following repoze.what predicate (not
 > tested):
 >
 >     from repoze.what.predicates import Predicate
 >
 >     class from_ip(Predicate):
 >         message = 'The user must have the IP address "%(ip_address)s"'
 >         def __init__(self, ip_address, **kwargs):
 >             super(from_ip, self).__init__(**kwargs)
 >             self.ip_address = ip_address
 >         def evaluate(self, environ, credentials):
 >             if self.ip_address != environ.get('REMOTE_ADDR'):
 >                 self.unmet()
 >
 > HTH.

Thanks, just tested that and it works as espected. At least so long as 
you use it in a require decorator.

But what is the recommended way to check this same predicate in a 
condition inside a template (e.g. I want to show a link to the 
restricted page only when the user has the required ip address)?

Also, is it possible to automatically associate the required ip address 
with a certain user (or group or permission) in the database so that I 
have request.identity already set up properly when somebody logs in from 
the required ip address? I.e. I really want to have IP based 
authentication, not only authorization. I guess I must write a 
repoze.who authenticator plugin for that?

-- Christoph

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to