Changeset 649

Show
Ignore:
Timestamp:
11/23/06 08:40:30
Author:
crchemist
Message:

Added posibility of selection among static and dynamic captchas.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneCaptchas/trunk/Extensions/Install.py

    r648 r649  
    1616    if not hasattr(portal, TOOL_ID): 
    1717        constructTransientObjectContainer(portal, id=TOOL_ID, timeout_mins=60) 
    18      
     18 
    1919    safeEditProperty(self, 'captcha_key', generateKey(8)) 
     20 
    2021    Layers = [] 
    2122    Layers += LAYERS 
     23 
     24    if static_captchas or (not havePIL): 
     25        Layers.append(LAYER_STATIC_CAPTCHAS) 
     26    else: 
     27        Layers.append(LAYER_DYNAMIC_CAPTCHAS) 
     28 
    2229    qi = getToolByName(self, 'portal_quickinstaller') 
    2330    mtool = getToolByName(self, 'portal_migration') 
    2431    plone_version = mtool.getFileSystemVersion() 
    25      
     32 
    2633    if plone_version.startswith('2.1'): 
    2734        plone_version = '2.1.2' 
     
    3946    discussion_layer = DiscussionLayer+'/'+plone_version 
    4047    Layers.append(discussion_layer) 
     48     
     49 
    4150    out.write('Call setupSkin... \n') 
    4251    setupSkin(self, out, Layers) 
  • qPloneCaptchas/trunk/config.py

    r648 r649  
    22PRODUCT_NAME = 'qPloneCaptchas' 
    33CAPTCHAS_COUNT = 165 
    4 LAYERS = ['captchas', 'plone_captchas'
     4LAYERS = ['captchas'
    55LAYER_DISCUSSION = 'captchas_discussion' 
    66LAYER_FORMMAILER = 'captchas_ploneformmailer' 
    7 ALL_LAYERS = LAYERS + [LAYER_DISCUSSION, LAYER_FORMMAILER] 
     7LAYER_DYNAMIC_CAPTCHAS = 'plone_captchas' 
     8LAYER_STATIC_CAPTCHAS = 'plone_captchas_static' 
     9ALL_LAYERS = LAYERS + [LAYER_DISCUSSION, LAYER_FORMMAILER, LAYER_STATIC_CAPTCHAS, LAYER_DYNAMIC_CAPTCHAS] 
    810TOOL_ICON = 'tool.gif' 
    911TOOL_ID = 'portal_captchas' 
    10 havePIL = True 
     12 
     13try: 
     14    import PIL 
     15    havePIL = True 
     16except: 
     17    havePIL = False 
     18 
     19static_captchas = True 
  • qPloneCaptchas/trunk/skins/plone_captchas/captcha_validator.vpy

    r648 r649  
    1 from Products.qPloneCaptchas.config import havePIL 
    21from Products.qPloneCaptchas.utils import decrypt, parseKey, \ 
    32     encrypt1, getWord, addExpiredKey 
     
    1615date = parsed_key['date'] 
    1716 
    18 if havePIL: 
    19     enc = test_key 
    20     solution = getWord(int(index)) 
    21 else: 
    22     img = getattr(context, '%s.jpg' % index) 
    23     solution = img.title 
    24     enc = encrypt1(test_key) 
     17enc = test_key 
     18solution = getWord(int(index)) 
    2519 
    2620if (enc != solution) or (context.portal_captchas.has_key(decrypted_key)) \ 
  • qPloneCaptchas/trunk/skins/plone_captchas/getCaptcha.py

    r648 r649  
    1010     encrypt 
    1111 
    12 from Products.qPloneCaptchas.config import havePIL 
    1312from random import randint 
    14 key = formKey(randint(0, getCaptchasCount(havePIL))) 
     13key = formKey(randint(0, getCaptchasCount(True))) 
    1514encrypted_key = encrypt(context.captcha_key, key) 
    1615 
  • qPloneCaptchas/trunk/skins/plone_captchas/getCaptchaImage.py

    r648 r649  
    99from Products.qPloneCaptchas.utils import gen_captcha, decrypt, \ 
    1010     getWord, parseKey 
    11 from Products.qPloneCaptchas.config import havePIL 
     11 
    1212hk = context.REQUEST.traverse_subpath[0] 
    1313dk = decrypt(context.captcha_key, hk) 
    1414key = parseKey(dk)['key'] 
     15im = gen_captcha(getWord(int(key)), 27) 
    1516 
    16 if havePIL: 
    17     im = gen_captcha(getWord(int(key)), 27) 
    18     context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpeg') 
    19     context.REQUEST.RESPONSE.setHeader('Content-Length', im['size']) 
    20     context.REQUEST.RESPONSE.setHeader('Accept-Ranges', 'bytes') 
    21     return im['src'] 
    22 else: 
    23     img = getattr(context, '%s.jpg' % key) 
    24     return img.index_html(context.REQUEST, context.REQUEST.RESPONSE) 
     17context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpeg') 
     18context.REQUEST.RESPONSE.setHeader('Content-Length', im['size']) 
     19context.REQUEST.RESPONSE.setHeader('Accept-Ranges', 'bytes') 
     20return im['src']