Changeset 7297


Ignore:
Timestamp:
7 Dec 2011, 05:51:08 (13 years ago)
Author:
uli
Message:

Change verify interface for captchas: expect HTTP requests instead of
CaptchaRequest? instances.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/captcha.py

    r7296 r7297  
    6565class ICaptcha(Interface):
    6666
    67     def verify(request_data):
    68         """Verify data entered in a request.
    69 
    70         Expects some ICaptchaRequest object and returns an
     67    def verify(request):
     68        """Verify data entered in an HTTP request.
     69
     70        Expects some IHTTPRequest object and returns an
    7171        ICaptchaResponse indicating that the solution was correct or
    7272        not.
     
    173173    grok.implements(ICaptcha)
    174174
    175     def verify(self, captcha_request):
     175    def verify(self, request):
    176176        return CaptchaResponse(True, None)
    177177
     
    191191    grok.implements(ICaptcha)
    192192
     193    #: name of solution field in HTTP request
     194    sol_field = 'solution'
     195    #: name of challenge field in HTTP request
     196    chal_field = 'challenge'
     197
    193198    def verify(self, request):
    194         if request.solution == request.challenge and request.solution:
     199        form = getattr(request, 'form', {})
     200        solution=form.get(self.sol_field, None)
     201        challenge=form.get(self.chal_field, None)
     202        if solution == challenge and solution:
    195203            return CaptchaResponse(is_valid=True)
    196204        return CaptchaResponse(is_valid=False)
Note: See TracChangeset for help on using the changeset viewer.