All,
 
I have a site that uses CookieCrumbler for user login. I need to track how many incorrect login attempts a user makes. I am trying to use a python generator to do this but it makes Zope hang when I try to do an invalid login (eg. no password or incorrect password). Here's a snippet:
 
 def make_counter(x):
        while 1:
            yield x
            x = x + 1
 
    counter = make_counter(1)
 
    security.declarePublic('getUnauthorizedURL')
    def getUnauthorizedURL(self):
        '''
        Redirects to the login page.
        '''
        req = self.REQUEST
        resp = req['RESPONSE']
        attempt = getattr(req, '_cookie_auth', ATTEMPT_NONE)
        if attempt == ATTEMPT_NONE:
            # An anonymous user was denied access to something.
            page_id = self.auto_login_page
            retry = ''
        elif attempt == ATTEMPT_LOGIN:
            # The login attempt failed.  Try again.
            page_id = self.auto_login_page
            #retry = '1'
            retry = counter.next()
 
I added the make_counter function. It seems the culprit is the retry = counter.next() bit. I tried doing this same thing with the make_counter function in an External method and then calling it from a python script like so:
counter = context.make_counter(1)
return counter.next()
 
In that case, an unauthorized exception is raised complaining about next. I can however, just return the counter which gives me <generator object at 0xb48d56cc>. Am I calling the next method incorrectly or is there something else I'm missing or being dumb about?
 
Thanks,
Tom Palermo
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to