Changeset 362


Ignore:
Timestamp:
21.01.2009 13:50:49 (3 years ago)
Author:
mike
Message:
  • added ReCaptcha?-service
  • added PILCaptcha-service
Location:
CMESS/captcha/trunk/com/zms/captcha
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • CMESS/captcha/trunk/com/zms/captcha/README.txt

    r329 r362  
    1616ICONS, http://famfamfam.com 
    1717CAPTCHAS.NET, http://captchas.net 
     18RECAPTCHA.NET, http://recaptcha.net 
     19PIL, http://www.pythonware.com/products/pil/ 
    1820 
    1921LICENSE: Creative Commons Attribution-Share Alike 2.0 Germany 
     
    2325HISTORY 
    2426 
     27v1.1.0.200901211350 
     28- added ReCaptcha-service 
     29- added PILCaptcha-service  
     30 
    2531v1.0.0.200811281134 
    2632- configuration via meta-object (attr_captcha) 
    27 - captcha-services "captcha.net" and "static_pics" integrated 
     33- captcha-services "captchas.net" and "static_pics" integrated 
    2834- wrapper for different captcha-services (captcha_getContent, captcha_isValid) 
    2935 
  • CMESS/captcha/trunk/com/zms/captcha/c_captcha_basic.py

    r355 r362  
    11from com.zms.captcha.CaptchasDotNet import CaptchasDotNet 
     2from com.zms.captcha.PILCaptcha import * 
    23from com.zms.captcha.reCaptcha import * 
    34 
    45class C_Captcha_Basic: 
    5         def __init__(self): 
    6                 self.id = None 
     6        def __init__(self, zms_context): 
     7                self.id                                         = None 
     8                 
     9                self.zms_context        = zms_context 
     10                self.zms_lang                   = self.zms_context.REQUEST.get('lang', self.zms_context.getPrimaryLanguage()) 
    711                 
    812        def GetContent(self): 
     
    1923class C_Captcha_Dot_Net(C_Captcha_Basic): 
    2024        def __init__(self, zms_context): 
     25                C_Captcha_Basic.__init__(self, zms_context) 
     26                 
    2127                temp_client             = zms_context.attr_captcha.getObjProperty('captchaClient', zms_context.REQUEST) 
    2228                temp_secret             = zms_context.attr_captcha.getObjProperty('captchaSecret', zms_context.REQUEST) 
     
    2733                self.id                                         = 'captchas.net' 
    2834                self.captcha                    = CaptchasDotNet(temp_client, temp_secret, alphabet = temp_chars) 
    29                 self.zms_context        = zms_context 
    30                 self.zms_lang                   = self.zms_context.REQUEST.get('lang', self.zms_context.getPrimaryLanguage()) 
    31                  
     35                                 
    3236        def GetContent(self): 
    3337                temp_result = '<input type="hidden" name="captcha_random" value="%s" />'%self.captcha.random() 
     
    5155                         
    5256                return temp_result 
     57 
     58class C_PIL_Captcha(C_Captcha_Basic): 
     59        def __init__(self, zms_context): 
     60                C_Captcha_Basic.__init__(self, zms_context) 
     61                 
     62                self.id = 'PILCaptcha' 
    5363         
     64        def GetContent(self): 
     65                temp_img = generateImage(self.zms_context.temp_folder,  
     66                                                                                                                        self.zms_context.attr_captcha.getObjProperty('pilcaptchaCharCount', self.zms_context.REQUEST),  
     67                                                                                                                        self.zms_context.attr_captcha.getObjProperty('pilcaptchaFontSize', self.zms_context.REQUEST), 
     68                                                                                                                        self.zms_context.REQUEST) 
     69                 
     70                temp_result = '<img src="%s" />'%temp_img.absolute_url() + '<br />'  
     71                temp_result += '<input type="submit" name="captcha_new" value="%s" /><br />'%self.zms_context.getLangStr('captchaNewCode', self.zms_lang) 
     72                temp_result += '<label>%s</label><br />'%self.zms_context.getLangStr('captchaLabel', self.zms_lang) 
     73                temp_result += '<input type="text" name="captcha_password" size="16" />' 
     74                 
     75                return temp_result 
     76         
     77        def IsCodeValid(self): 
     78                if (self.zms_context.REQUEST.SESSION['sess_captcha'] == self.zms_context.REQUEST.form.get('captcha_password', '')): 
     79                        temp_result = (True, '') 
     80                else: 
     81                        temp_result = (False, self.zms_context.getLangStr('captchaWrongVerification', self.zms_lang)) 
     82                 
     83                return temp_result 
     84 
    5485class C_ReCaptcha(C_Captcha_Basic): 
    5586        def __init__(self, zms_context): 
    56                 self.id                                         = 'reCaptcha' 
    57                 self.zms_context        = zms_context 
    58                 self.zms_lang                   = self.zms_context.REQUEST.get('lang', self.zms_context.getPrimaryLanguage()) 
     87                C_Captcha_Basic.__init__(self, zms_context) 
     88                 
     89                self.id = 'reCaptcha' 
    5990         
    6091        def GetContent(self): 
  • CMESS/captcha/trunk/com/zms/captcha/c_handler_captcha.py

    r355 r362  
    11from com.zms.captcha.c_captcha_basic import C_Captcha_Basic 
    22from com.zms.captcha.c_captcha_basic import C_Captcha_Dot_Net 
     3from com.zms.captcha.c_captcha_basic import C_PIL_Captcha 
    34from com.zms.captcha.c_captcha_basic import C_ReCaptcha 
    45 
     
    89                        if (zms_context.attr_captcha.getObjProperty('captchaService', zms_context.REQUEST) == 'captchas.net'): 
    910                                self.captcha_obj = C_Captcha_Dot_Net(zms_context) 
     11                        elif (zms_context.attr_captcha.getObjProperty('captchaService', zms_context.REQUEST) == 'PILCaptcha'): 
     12                                self.captcha_obj = C_PIL_Captcha(zms_context) 
    1013                        elif (zms_context.attr_captcha.getObjProperty('captchaService', zms_context.REQUEST) == 'reCaptcha'): 
    1114                                self.captcha_obj = C_ReCaptcha(zms_context) 
  • CMESS/captcha/trunk/com/zms/captcha/zms/captcha.metaobj.xml

    r355 r362  
    1616                        $("#tr_captchaClient").show(); 
    1717                        $("#tr_captchaSecret").show(); 
     18                        $("#captchaInfo").show(); 
    1819                } 
    1920                else 
     
    2122                        $("#tr_captchaClient").hide(); 
    2223                        $("#tr_captchaSecret").hide(); 
     24                        $("#captchaInfo").hide();                        
    2325                } 
    2426        } 
     
    3032                        $("#tr_recaptchaPublicKey").show(); 
    3133                        $("#tr_recaptchaPrivateKey").show(); 
     34                        $("#recaptchaInfo").show(); 
    3235                } 
    3336                else 
     
    3538                        $("#tr_recaptchaPublicKey").hide(); 
    3639                        $("#tr_recaptchaPrivateKey").hide(); 
     40                        $("#recaptchaInfo").hide();                      
     41                } 
     42        } 
     43         
     44        function changeVisibilityServicePILCaptcha(show) 
     45        { 
     46                if (show) 
     47                { 
     48                        $("#tr_pilcaptchaCharCount").show(); 
     49                        $("#tr_pilcaptchaFontSize").show(); 
     50                        $("#pilcaptchaInfo").show();                     
     51                } 
     52                else 
     53                { 
     54                        $("#tr_pilcaptchaCharCount").hide(); 
     55                        $("#tr_pilcaptchaFontSize").hide(); 
     56                        $("#pilcaptchaInfo").hide();                     
    3757                } 
    3858        } 
     
    5070                changeVisibilityServiceDotNet(isEnabled() && ($("#captchaService_<dtml-var lang>").attr('value') == 'captchas.net')); 
    5171                changeVisibilityServiceReCaptcha(isEnabled() && ($("#captchaService_<dtml-var lang>").attr('value') == 'reCaptcha')); 
     72                changeVisibilityServicePILCaptcha(isEnabled() && ($("#captchaService_<dtml-var lang>").attr('value') == 'PILCaptcha')); 
    5273        } 
    5374         
     
    85106<item key="keys" type="list"><list> 
    86107<item><![CDATA[captchas.net]]></item> 
     108<item><![CDATA[PILCaptcha]]></item> 
    87109<item><![CDATA[reCaptcha]]></item> 
    88110<item><![CDATA[static_pics]]></item> 
     
    97119</item> 
    98120<item type="dictionary"><dictionary> 
     121<item key="id"><![CDATA[captchaInfo]]></item> 
     122<item key="mandatory" type="int">0</item> 
     123<item key="multilang" type="int">0</item> 
     124<item key="name"><![CDATA[</td></tr><tr id="captchaInfo"><td></td><td class="form-text"><strong>Hint:</strong> more information at <a href="http://captchas.net/" target="_blank">captchas.net</a>]]></item> 
     125<item key="repetitive" type="int">0</item> 
     126<item key="type"><![CDATA[hint]]></item> 
     127</dictionary> 
     128</item> 
     129<item type="dictionary"><dictionary> 
    99130<item key="default"><![CDATA[demo]]></item> 
    100131<item key="id"><![CDATA[captchaClient]]></item> 
     
    117148</item> 
    118149<item type="dictionary"><dictionary> 
     150<item key="id"><![CDATA[recaptchaInfo]]></item> 
     151<item key="mandatory" type="int">0</item> 
     152<item key="multilang" type="int">0</item> 
     153<item key="name"><![CDATA[</td></tr><tr id="recaptchaInfo"><td></td><td class="form-text"><strong>Hint:</strong> get your public/private key at <a href="http://recaptcha.net/" target="_blank">recaptcha.net</a>]]></item> 
     154<item key="repetitive" type="int">0</item> 
     155<item key="type"><![CDATA[hint]]></item> 
     156</dictionary> 
     157</item> 
     158<item type="dictionary"><dictionary> 
    119159<item key="id"><![CDATA[recaptchaPublicKey]]></item> 
    120160<item key="mandatory" type="int">0</item> 
     
    132172<item key="repetitive" type="int">0</item> 
    133173<item key="type"><![CDATA[string]]></item> 
     174</dictionary> 
     175</item> 
     176<item type="dictionary"><dictionary> 
     177<item key="id"><![CDATA[pilcaptchaInfo]]></item> 
     178<item key="mandatory" type="int">0</item> 
     179<item key="multilang" type="int">0</item> 
     180<item key="name"><![CDATA[</td></tr><tr id="pilcaptchaInfo"><td></td><td class="form-text"><strong>Hint:</strong> Python Imaging Library (<a href="http://www.pythonware.com/products/pil/" target="_blank">PIL</a>) is required]]></item> 
     181<item key="repetitive" type="int">0</item> 
     182<item key="type"><![CDATA[hint]]></item> 
     183</dictionary> 
     184</item> 
     185<item type="dictionary"><dictionary> 
     186<item key="default"><![CDATA[5]]></item> 
     187<item key="id"><![CDATA[pilcaptchaCharCount]]></item> 
     188<item key="mandatory" type="int">0</item> 
     189<item key="multilang" type="int">1</item> 
     190<item key="name"><![CDATA[Char Count]]></item> 
     191<item key="repetitive" type="int">0</item> 
     192<item key="type"><![CDATA[int]]></item> 
     193</dictionary> 
     194</item> 
     195<item type="dictionary"><dictionary> 
     196<item key="default"><![CDATA[36]]></item> 
     197<item key="id"><![CDATA[pilcaptchaFontSize]]></item> 
     198<item key="mandatory" type="int">0</item> 
     199<item key="multilang" type="int">1</item> 
     200<item key="name"><![CDATA[Font Size]]></item> 
     201<item key="repetitive" type="int">0</item> 
     202<item key="type"><![CDATA[int]]></item> 
    134203</dictionary> 
    135204</item> 
     
    189258<item key="name"><![CDATA[CaptchaConfig]]></item> 
    190259<item key="package"><![CDATA[com.zms.captcha]]></item> 
    191 <item key="revision"><![CDATA[1.0.0]]></item> 
     260<item key="revision"><![CDATA[1.1.0]]></item> 
    192261<item key="type"><![CDATA[ZMSResource]]></item> 
    193262</dictionary> 
     
    467536<item key="name"><![CDATA[CaptchaLib]]></item> 
    468537<item key="package"><![CDATA[com.zms.captcha]]></item> 
    469 <item key="revision"><![CDATA[1.0.0]]></item> 
     538<item key="revision"><![CDATA[1.1.0]]></item> 
    470539<item key="type"><![CDATA[ZMSLibrary]]></item> 
    471540</dictionary> 
     
    479548</list> 
    480549</item> 
    481 <item key="enabled" type="int">1</item> 
     550<item key="access" type="dictionary"><dictionary> 
     551<item key="delete" type="list"><list> 
     552</list> 
     553</item> 
     554<item key="delete_custom"></item> 
     555<item key="edit" type="list"><list> 
     556</list> 
     557</item> 
     558<item key="edit_custom"></item> 
     559<item key="insert" type="list"><list> 
     560</list> 
     561</item> 
     562<item key="insert_custom"></item> 
     563</dictionary> 
     564</item> 
     565<item key="enabled" type="int">0</item> 
    482566<item key="id"><![CDATA[com.zms.captcha]]></item> 
    483567<item key="name"><![CDATA[com.zms.captcha]]></item> 
    484568<item key="package"></item> 
    485 <item key="revision"><![CDATA[1.0.0]]></item> 
     569<item key="revision"><![CDATA[1.1.0]]></item> 
    486570<item key="type"><![CDATA[ZMSPackage]]></item> 
    487571</dictionary> 
Note: See TracChangeset for help on using the changeset viewer.