commit 1bc823d54b507438972b53cc6774de7c6d626ab4 Author: Isis Lovecruft isis@torproject.org Date: Tue Mar 25 22:24:10 2014 +0000
Change ReCaptchaProtectedResource.checkResponse() to also return request.
We need to return the original request, not just the boolean representing the validity of the CAPTCHA solution, if we want to be able to interact with the original request while rendering it. --- lib/bridgedb/HTTPServer.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lib/bridgedb/HTTPServer.py b/lib/bridgedb/HTTPServer.py index 26bfb6d..e2f1059 100644 --- a/lib/bridgedb/HTTPServer.py +++ b/lib/bridgedb/HTTPServer.py @@ -419,8 +419,11 @@ class ReCaptchaProtectedResource(CaptchaProtectedResource): ``'captcha_challenge_field'``, and the other, ``'captcha_response_field'``. These POST arguments should be obtained from :meth:`render_GET`. - :rtupe: bool - :returns: True, if the CAPTCHA solution was valid; False otherwise. + :rtupe: :api:`twisted.internet.defer.Deferred` + :returns: the returned deferred will callback with a tuple of + (``bool``, :api:`twisted.web.server.Request`). If the CAPTCHA + solution was valid, a tuple will contain ``(True, request)``; + otherwise, it will contain ``(False, request)``. """ challenge, response = self.extractClientSolution(request) clientIP = self.getClientIP(request) @@ -429,18 +432,18 @@ class ReCaptchaProtectedResource(CaptchaProtectedResource): logging.debug("Captcha from %r. Parameters: %r" % (Util.logSafely(clientIP), request.args))
- def checkResponse(solution, clientIP): + def checkResponse(solution, request): if solution.is_valid: logging.info("Valid CAPTCHA solution from %r." % Util.logSafely(clientIP)) - return True + return (True, request) else: logging.info("Invalid CAPTCHA solution from %r: %r" % (Util.logSafely(clientIP), solution.error_code)) - return False + return (False, request)
d = txrecaptcha.submit(challenge, response, self.recaptchaPrivKey, - remoteIP).addCallback(checkResponse, clientIP) + remoteIP).addCallback(checkResponse, request) return d
def render_GET(self, request):
tor-commits@lists.torproject.org