Changeset 678

Show
Ignore:
Timestamp:
12/01/06 11:56:48
Author:
crchemist
Message:

Added new fields to configlet.

Files:

Legend:

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

    r677 r678  
    1717 
    1818    safeEditProperty(self, 'captcha_key', generateKey(8)) 
     19 
     20    # add Property sheet to portal_properies 
     21    pp = getToolByName(self, 'portal_properties') 
     22    if not 'qPloneCaptchas' in pp.objectIds(): 
     23        pp.addPropertySheet(id='qPloneCaptchas', title= '%s Properties' % 'qPloneCaptchas') 
     24        out.write("Adding %s property sheet to portal_properies\n" % 'qPloneComments' ) 
     25    props_sheet = pp['qPloneCaptchas'] 
     26    updateProperties(props_sheet, out, PROPERTIES) 
     27 
     28 
    1929 
    2030    Layers = [] 
     
    8797    controlpanel_tool = getToolByName(self, 'portal_controlpanel') 
    8898    controlpanel_tool.unregisterConfiglet(CONFIGLET_ID) 
     99    # Remove Product's property sheet from portal_properties 
     100    pp = getToolByName(self, 'portal_properties') 
     101    if 'qPloneCaptchas' in pp.objectIds(): 
     102        pp.manage_delObjects(ids=('qPloneCaptchas',)) 
    89103 
    90104def updateProperties(pp_ps, out, *args): 
     
    104118        addTool = self.manage_addProduct['qPloneCaptchas'].manage_addTool 
    105119        addTool('CaptchaTool') 
     120 
     121def updateProperties(pp_ps, out, *args): 
     122    for prop in args: 
     123        for prop_id, prop_value, prop_type in prop: 
     124            if not pp_ps.hasProperty(prop_id): 
     125                pp_ps.manage_addProperty(prop_id, prop_value, prop_type) 
     126                out.write("Adding %s property to %s property sheet\n" % (prop_id, 'qPloneComments')) 
  • qPloneCaptchas/trunk/config.py

    r677 r678  
    1212CONFIGLET_ID = "prefs_captchas_setup_form" 
    1313CONFIGLET_NAME = "qPloneCaptchas setup" 
    14 PROPERTIES = (('static_captchas', 'True', 'boolean'),) 
     14 
     15DEFAULT_IMAGE_SIZE = 27 
     16DEFAULT_BG = 'gray' 
     17DEFAULT_FONT_COLOR = 'black' 
     18DEFAULT_PERIOD = 0.05 
     19DEFAULT_AMPLITUDE = 5 
     20DEFAULT_OFFSET = (0.5, 0.5) 
     21DEFAULT_DISTORTION = [DEFAULT_PERIOD, DEFAULT_AMPLITUDE, DEFAULT_OFFSET] 
     22 
     23PROPERTIES = (('image_size', DEFAULT_IMAGE_SIZE, 'int'), 
     24              ('background', DEFAULT_BG, 'string'), 
     25              ('font_color', DEFAULT_FONT_COLOR, 'string'), 
     26              ('period', DEFAULT_PERIOD, 'float'), 
     27              ('amplitude', DEFAULT_AMPLITUDE, 'float'), 
     28              ('random_params', True, 'boolean')) 
    1529 
    1630try: 
  • qPloneCaptchas/trunk/skins/plone_captchas/dynamic/getCaptchaImage.py

    r677 r678  
    99from Products.qPloneCaptchas.utils import gen_captcha, decrypt, \ 
    1010     getWord, parseKey 
     11from Products.CMFCore.utils import getToolByName 
     12 
     13propTool = getToolByName(context, 'portal_properties') 
     14captchaProps = propTool['qPloneCaptchas'] 
     15 
     16period = captchaProps.getProperty('period') 
     17amplitude = captchaProps.getProperty('amplitude') 
    1118 
    1219hk = context.REQUEST.traverse_subpath[0] 
    1320dk = decrypt(context.captcha_key, hk) 
    1421key = parseKey(dk)['key'] 
    15 im = gen_captcha(getWord(int(key)), 27) 
     22kwargs = {'text': getWord(int(key)), 
     23          'size': captchaProps.getProperty('image_size'), 
     24          'bkground': captchaProps.getProperty('background'), 
     25          'font_color': captchaProps.getProperty('font_color'), 
     26          'distortion':[period, amplitude, (0.0, 0.0)]} 
     27 
     28im = gen_captcha(**kwargs) 
    1629 
    1730context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpeg') 
  • qPloneCaptchas/trunk/skins/plone_captchas/prefs_captchas_setup_form.cpt

    r677 r678  
    1 <html xmlns="http://www.w3.org/1999/xhtml" 
    2       xml:lang="en" 
     1<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" 
    32      lang="en" 
    43      i18n:domain="plonecaptchas" 
    54      metal:use-macro="here/prefs_main_template/macros/master"> 
     5 
     6<metal:block fill-slot="top_slot" 
     7             tal:define="dummy python:request.set('disable_border',1)" /> 
    68 
    79<body> 
     
    1214    <div metal:define-macro="main" i18n:domain="plonecaptchas"> 
    1315    <div class="configlet"> 
    14     <div class="documentEditable"> 
    15  
    16     <div class="contentActions"> 
    17     &nbsp; 
    18     </div> 
    19     <div class="documentContent" metal:define-slot="prefs_content"> 
    2016        <h1 i18n:translate="heading_comments_setup">Plone Captchas Setup</h1> 
    2117 
     
    5551            </fieldset> 
    5652 
    57             <fieldset> 
    58                 <legend i18n:translate="legend_setup_options">captcha image setup options</legend> 
    59                 <div tal:define="ct here/getCaptchaType;"> 
    60                     <input name="static_captchas" 
    61                            id="use_static_captchas" 
    62                            type="radio" 
    63                            value="static" 
    64                            tal:attributes="checked python:test(ct=='static', 'checked', '')"/> 
    65                     <label for="use_static_captchas">Use static captchas</label> 
    66                     <br /> 
    67                     <input name="static_captchas" 
    68                            id="use_dynamic_captchas" 
    69                            type="radio" 
    70                            disabled="" 
    71                            value="dynamic" 
    72                            tal:attributes="checked python:test(ct=='dynamic', 'checked', ''); 
    73                                            disabled python:test(context.checkPIL(), '', 'disabled');"/> 
    74                     <label for="use_dynamic_captchas">Use dynamic captchas</label> 
     53            <fieldset tal:define="props_sheet here/portal_properties/qPloneCaptchas"> 
     54                <legend i18n:translate="legend_setup_options">Dynamic captchas image setup options</legend> 
     55 
     56                <div class="field" 
     57                     tal:define="property_id string:image_size; 
     58                                 prop_value python:props_sheet.getProperty(property_id, None);" 
     59                     tal:condition="python:props_sheet.hasProperty(property_id)"> 
     60 
     61                    <input type="text" 
     62                           name="" 
     63                           id="" 
     64                           tabindex ="" 
     65                           tal:attributes="name property_id; 
     66                                           id property_id; 
     67                                           value prop_value; 
     68                                           tabindex tabindex/next;"/> 
     69 
     70                    <label i18n:translate="string:${property_id}" 
     71                           for="" 
     72                           tal:attributes="for string:${property_id}"> 
     73                           Font size 
     74                    </label> 
    7575                </div> 
     76 
     77                <div class="field" 
     78                     tal:define="property_id string:background; 
     79                                 prop_value python:props_sheet.getProperty(property_id, None);" 
     80                     tal:condition="python:props_sheet.hasProperty(property_id)"> 
     81 
     82                    <input type="text" 
     83                           name="" 
     84                           id="" 
     85                           tabindex ="" 
     86                           tal:attributes="name property_id; 
     87                                           id property_id; 
     88                                           value prop_value; 
     89                                           tabindex tabindex/next;"/> 
     90 
     91                    <label i18n:translate="string:${property_id}" 
     92                           for="" 
     93                           tal:attributes="for string:${property_id}"> 
     94                           Background 
     95                    </label> 
     96                </div> 
     97 
     98                <div class="field" 
     99                     tal:define="property_id string:font_color; 
     100                                 prop_value python:props_sheet.getProperty(property_id, None);" 
     101                     tal:condition="python:props_sheet.hasProperty(property_id)"> 
     102 
     103                    <input type="text" 
     104                           name="" 
     105                           id="" 
     106                           tabindex ="" 
     107                           tal:attributes="name property_id; 
     108                                           id property_id; 
     109                                           value prop_value; 
     110                                           tabindex tabindex/next;"/> 
     111 
     112                    <label i18n:translate="string:${property_id}" 
     113                           for="" 
     114                           tal:attributes="for string:${property_id}"> 
     115                           Font color 
     116                    </label> 
     117                </div> 
     118 
     119                <div class="field" 
     120                     tal:define="property_id string:period; 
     121                                 prop_value python:props_sheet.getProperty(property_id, None);" 
     122                     tal:condition="python:props_sheet.hasProperty(property_id)"> 
     123 
     124                    <input type="text" 
     125                           name="" 
     126                           id="" 
     127                           tabindex ="" 
     128                           tal:attributes="name property_id; 
     129                                           id property_id; 
     130                                           value prop_value; 
     131                                           tabindex tabindex/next;"/> 
     132 
     133                    <label i18n:translate="string:${property_id}" 
     134                           for="" 
     135                           tal:attributes="for string:${property_id}"> 
     136                           Period 
     137                    </label> 
     138                </div> 
     139 
     140                <div class="field" 
     141                     tal:define="property_id string:amplitude; 
     142                                 prop_value python:props_sheet.getProperty(property_id, None);" 
     143                     tal:condition="python:props_sheet.hasProperty(property_id)"> 
     144 
     145                    <input type="text" 
     146                           name="" 
     147                           id="" 
     148                           tabindex ="" 
     149                           tal:attributes="name property_id; 
     150                                           id property_id; 
     151                                           value prop_value; 
     152                                           tabindex tabindex/next;"/> 
     153 
     154                    <label i18n:translate="string:${property_id}" 
     155                           for="" 
     156                           tal:attributes="for string:${property_id}"> 
     157                           Amplitude 
     158                    </label> 
     159                </div> 
     160 
     161                <div class="field" 
     162                     tal:define="property_id string:random_params; 
     163                                 prop_value python:props_sheet.getProperty(property_id, None);" 
     164                     tal:condition="python:props_sheet.hasProperty(property_id)"> 
     165 
     166                    <input type="checkbox" 
     167                           name="" 
     168                           id="" 
     169                           tabindex ="" 
     170                           tal:attributes="name property_id; 
     171                                           id property_id; 
     172                                           value prop_value; 
     173                                           tabindex tabindex/next;"/> 
     174 
     175                    <label i18n:translate="string:${property_id}" 
     176                           for="" 
     177                           tal:attributes="for string:${property_id}"> 
     178                           Random values 
     179                    </label> 
     180                </div> 
     181 
    76182            </fieldset> 
    77183 
     
    89195    </div> 
    90196    </div> 
    91     </div> 
    92     </div> 
    93197</div> 
    94198</body> 
  • qPloneCaptchas/trunk/utils.py

    r677 r678  
    44from random import randint 
    55from Products.qPloneCaptchas.data import basic_english 
    6 from Products.qPloneCaptchas.config import havePIL, CAPTCHAS_COUNT 
     6from Products.qPloneCaptchas.config import * 
    77from DateTime import DateTime 
    88import re 
     
    1515    return md5.new(s).hexdigest().upper() 
    1616 
    17 def gen_captcha(text, fnt_sz, fmt='JPEG'): 
     17def gen_captcha(**kwargs): 
    1818    """Generate a captcha image""" 
    1919    import ImageFile 
     
    2828    from cStringIO import StringIO 
    2929 
    30     amplitude = random.uniform(3, 6.5)  
    31     period = random.uniform(0.04, 0.1) 
    32     offset = (random.uniform(0, math.pi * 2 / period), 
    33               random.uniform(0, math.pi * 2 / period)) 
     30    if kwargs.has_key('text'): 
     31        text = kwargs['text'] 
     32    else: 
     33        text = None 
     34 
     35    if kwargs.has_key('size'): 
     36        fnt_sz = kwargs['size'] 
     37    else: 
     38        fnt_sz = DEFAULT_IMAGE_SIZE 
     39 
     40    if kwargs.has_key('bkground'): 
     41        bkground = kwargs['bkground'] 
     42    else: 
     43        bkground = DEFAULT_BG 
     44 
     45    if kwargs.has_key('font_color'): 
     46        font_color = kwargs['font_color'] 
     47    else: 
     48        font_color = DEFAULT_FONT_COLOR 
     49 
     50    if kwargs.has_key('distortion'): 
     51        distortion = kwargs['distortion'] 
     52    else: 
     53        distortion = DEFAULT_DISTORTION 
     54 
     55    period = distortion[0] 
     56    amplitude = distortion[1] 
     57    offset = distortion[2] 
    3458 
    3559    def getTransform(image): 
     
    4670    FONT_PATH = DATA_PATH + '/fonts' 
    4771 
    48     fgcolor = 'black'; bgcolor = 'gray'; textColor='black' 
    49  
    5072    #select font for captcha text 
    5173    ALL_FONTS=('Bd', 'It', 'MoBI', 'Mono', 'Se', 'BI', 'MoBd', 'MoIt', 'SeBd', '') 
     
    5577 
    5678#------------------------------render   background1 ----------------------- 
    57     image = Image.new('RGB', (textSize[0]+10,textSize[1]+10), bgcolor
    58     image.paste(bgcolor
     79    image = Image.new('RGB', (textSize[0]+7,textSize[1]+7), bkground
     80    image.paste(bkground
    5981#------------------------------render       Text2 ------------------------ 
    6082    draw = ImageDraw.Draw(image) 
     
    6385    y = int((image.size[1] - textSize[1]) * alignment[1] + 0.5) 
    6486 
    65     draw.text((x,y), text, font=font, fill=textColor) 
     87    draw.text((x,y), text, font=font, fill=font_color) 
    6688 
    6789#------------------------------render       Distortion3 ----------------------- 
     
    107129    img = image.transform(image.size, Image.MESH, mesh, Image.BILINEAR) 
    108130 
    109 #--------------------------------------------------------------------------- 
    110131    # save the image to a file 
    111     img.save(outFile, format=fmt
     132    img.save(outFile, format='jpeg'
    112133    outFile.seek(0) 
    113134    src = outFile.read() 
     
    150171    return {'date': ps.group(1), 'key':ps.group(2)} 
    151172 
    152 """ 
    153 def addExpiredKey(context, key): 
    154     context.portal_captchas.new(key) 
    155 """ 
    156  
    157173def toHex(s): 
    158174    lst = []