durusmail: quixote-users: Re: Using _q_access? Any place for a _q_traverse?
Using _q_access? Any place for a _q_traverse?
2003-08-22
Re: Using _q_access? Any place for a _q_traverse?
2003-08-22
2003-08-22
Re: Using _q_access? Any place for a _q_traverse?
2003-08-22
2003-08-22
2003-08-23
2003-08-24
2003-08-24
2003-08-24
2003-08-24
2003-08-25
Re: Using _q_access? Any place for a _q_traverse?
Oleg Broytmann
2003-08-22
On Fri, Aug 22, 2003 at 09:55:57AM -0600, VanL wrote:
> I must not be using it correctly, then... would you mind posting a
> sample?  Do you have the _q_access take care of everything directly, or
> does it raise an AccessError which is caught by a _q_exception_handler?

   Yes, I do raise the error.

>  Either way, could you post a snippet?

from qlib.main import user_db, ResMonitAuth
res_monit_auth = ResMonitAuth(user_db, "ResourceMonitoring")

def _q_access(request): # User authorization
   res_monit_auth.authenticate(request)

...and somewhere deep inside .authenticate() I check login/password and do

   raise AuthorizationError(self.realm)

from quixote.errors import AccessError
class AuthorizationError(AccessError):
   status_code = 401
   title = "Not authorized"
   description = "You are not authorized to access this resource."

   def __init__(self, realm):
      AccessError.__init__(self)
      self.realm = realm

   def format(self, request):
      request.response.set_content_type("text/html")
      request.response.set_header("WWW-Authenticate", 'Basic realm="%s"' %
self.realm)
      return ''

Oleg.
--
     Oleg Broytmann            http://phd.pp.ru/            phd@phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

reply