예제 #1
0
 def clean(self, data):
     ip = get_request().META['REMOTE_ADDR']
     if self.do_hiding and not throttle_is_over_limit(ip, self.hide_class, self.hide_for):
         throttle_increment(ip, self.hide_class)
         return
     try:
         resp = captcha.submit(data.get("recaptcha_challenge_field", None),
                               data.get("recaptcha_response_field", None),
                               self.private_key, request.META['REMOTE_ADDR'])
     except Exception, e:
         #sys.stderr.write('Recaptcha failed!  %r\n' % (e))
         pass
예제 #2
0
 def render(self, name, value, attrs=None):
     attrs = self.build_attrs(attrs, name=name)
     ip = get_request().META['REMOTE_ADDR']
     if attrs['do_hiding'] and throttle_is_over_limit(ip, attrs['hide_class'], attrs['hide_for']):
         return u''
     html = []
     html.append("<div id=\"captcha\">")
     html.append("<script>var RecaptchaOptions = {theme : '%s'};</script>" % (attrs.get('theme', 'white')))
     html.append('<script type="text/javascript"')
     html.append('        src="https://api-secure.recaptcha.net/challenge?k=%s">' % (attrs['public_key']))
     html.append('</script>')
     html.append('<noscript>')
     html.append('  <iframe src="https://api-secure.recaptcha.net/noscript?k=%s"' % (attrs['public_key']))
     html.append('          height="300" width="500" frameborder="0"></iframe><br>')
     html.append('  <textarea name="recaptcha_challenge_field" rows="3" cols="40">')
     html.append('  </textarea>')
     html.append('  <input type="hidden" name="recaptcha_response_field" value="manual_challenge">')
     html.append('</noscript>')
     html.append(u"</div>")
     return mark_safe("\n".join(html))