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)
    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 =
I added the make_counter function. It seems the culprit is the retry = 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)
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?
Tom Palermo
Zope maillist  -
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to