Ignore:
Timestamp:
7 Dec 2011, 00:13:12 (13 years ago)
Author:
uli
Message:

First silly steps for IdCaptcha?.

File:
1 edited

Legend:

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

    r7292 r7296  
    2323import urllib
    2424import urllib2
     25from random import SystemRandom as random
    2526from zope import schema
    2627from zope.component import getUtilitiesFor, getUtility, queryUtility
     
    142143                            default=getUtility(ICaptcha))
    143144
    144 #
    145 # Trivial default captcha
    146 #
     145##
     146## Trivial default captcha
     147##
    147148class CaptchaResponse(object):
    148149    grok.implements(ICaptchaResponse)
     
    184185grok.global_utility(NullCaptcha, name=u'')
    185186
    186 #
    187 # ReCaptcha
    188 #
     187##
     188## TestCaptcha
     189##
     190class IdCaptcha(object):
     191    grok.implements(ICaptcha)
     192
     193    def verify(self, request):
     194        if request.solution == request.challenge and request.solution:
     195            return CaptchaResponse(is_valid=True)
     196        return CaptchaResponse(is_valid=False)
     197
     198    def display(self, error_code=None):
     199        challenge = list('abcdef')
     200        random().shuffle(challenge)
     201        challenge = ''.join(challenge)
     202        html = (
     203            u'<input type="hidden" name="challenge"'
     204            u'       value="%s" /><br />'
     205            u'Type: %s<br />'
     206            u'<input type="text" name="solution" /><br />' % (
     207                challenge, challenge))
     208        return html
     209
     210grok.global_utility(IdCaptcha, name=u'Testing captcha')
     211
     212
     213##
     214## ReCaptcha
     215##
    189216API_SSL_SERVER = "https://www.google.com/recaptcha/api"
    190217VERIFY_SERVER = "http://www.google.com"
Note: See TracChangeset for help on using the changeset viewer.