Changeset 355 for CMESS/captcha


Ignore:
Timestamp:
20.01.2009 10:20:42 (3 years ago)
Author:
mike
Message:
  • include reCaptcha-Service
Location:
CMESS/captcha/trunk/com/zms/captcha
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • CMESS/captcha/trunk/com/zms/captcha/c_captcha_basic.py

    r318 r355  
    11from com.zms.captcha.CaptchasDotNet import CaptchasDotNet 
     2from com.zms.captcha.reCaptcha import * 
    23 
    34class C_Captcha_Basic: 
     
    2425                temp_chars              += (temp_client != 'demo') and temp_chars.upper() + '0123456789' or '' 
    2526                 
    26                 self.id                                         = 'captcha.net' 
     27                self.id                                         = 'captchas.net' 
    2728                self.captcha                    = CaptchasDotNet(temp_client, temp_secret, alphabet = temp_chars) 
    2829                self.zms_context        = zms_context 
     
    5051                         
    5152                return temp_result 
     53         
     54class C_ReCaptcha(C_Captcha_Basic): 
     55        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()) 
     59         
     60        def GetContent(self): 
     61                temp_error = '' 
     62                temp_result = displayhtml(self.zms_context.attr_captcha.getObjProperty('recaptchaPublicKey', self.zms_context.REQUEST), True, temp_error) 
     63                 
     64                print(temp_error) 
     65                 
     66                return temp_result 
     67         
     68        def IsCodeValid(self): 
     69                temp_result = False 
     70                 
     71                temp_response   = submit(self.zms_context.REQUEST.form.get('recaptcha_challenge_field', ''), 
     72                                                                                                                self.zms_context.REQUEST.form.get('recaptcha_response_field', ''), 
     73                                                                                                                self.zms_context.attr_captcha.getObjProperty('recaptchaPrivateKey', self.zms_context.REQUEST),  
     74                                                                                                                '127.0.0.1') 
     75                 
     76                if (temp_response.is_valid): 
     77                        temp_result = (True, '') 
     78                else: 
     79                        #incorrect-captcha-sol 
     80                        if (temp_response.error_code == 'incorrect-captcha-sol'): 
     81                                temp_result = (False, self.zms_context.getLangStr('captchaWrongVerification', self.zms_lang)) 
     82                        #invalid-site-private-key 
     83                        else: 
     84                                temp_result = (False, self.zms_context.getLangStr('captchaInvalid', self.zms_lang)) 
     85                 
     86                return temp_result 
  • CMESS/captcha/trunk/com/zms/captcha/c_handler_captcha.py

    r319 r355  
    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_ReCaptcha 
    34 
    45class C_Handler_Captcha: 
    56        def __init__(self, zms_context): 
    67                try: 
    7                         if (zms_context.attr_captcha.getObjProperty('captchaService', zms_context.REQUEST) == 'captcha.net'): 
     8                        if (zms_context.attr_captcha.getObjProperty('captchaService', zms_context.REQUEST) == 'captchas.net'): 
    89                                self.captcha_obj = C_Captcha_Dot_Net(zms_context) 
     10                        elif (zms_context.attr_captcha.getObjProperty('captchaService', zms_context.REQUEST) == 'reCaptcha'): 
     11                                self.captcha_obj = C_ReCaptcha(zms_context) 
    912                        else: 
    1013                                self.captcha_obj = None 
  • CMESS/captcha/trunk/com/zms/captcha/zms/captcha.metaobj.xml

    r319 r355  
    2424        } 
    2525         
     26        function changeVisibilityServiceReCaptcha(show) 
     27        { 
     28                if (show) 
     29                { 
     30                        $("#tr_recaptchaPublicKey").show(); 
     31                        $("#tr_recaptchaPrivateKey").show(); 
     32                } 
     33                else 
     34                { 
     35                        $("#tr_recaptchaPublicKey").hide(); 
     36                        $("#tr_recaptchaPrivateKey").hide(); 
     37                } 
     38        } 
     39         
    2640        function checkEnabled() 
    2741        { 
     
    3448        function checkService() 
    3549        { 
    36                 changeVisibilityServiceDotNet(isEnabled() && ($("#captchaService_<dtml-var lang>").attr('value') == 'captcha.net')); 
     50                changeVisibilityServiceDotNet(isEnabled() && ($("#captchaService_<dtml-var lang>").attr('value') == 'captchas.net')); 
     51                changeVisibilityServiceReCaptcha(isEnabled() && ($("#captchaService_<dtml-var lang>").attr('value') == 'reCaptcha')); 
    3752        } 
    3853         
     
    6984<item key="id"><![CDATA[captchaService]]></item> 
    7085<item key="keys" type="list"><list> 
    71 <item><![CDATA[captcha.net]]></item> 
     86<item><![CDATA[captchas.net]]></item> 
     87<item><![CDATA[reCaptcha]]></item> 
    7288<item><![CDATA[static_pics]]></item> 
    7389</list> 
     
    96112<item key="multilang" type="int">1</item> 
    97113<item key="name"><![CDATA[Secret]]></item> 
     114<item key="repetitive" type="int">0</item> 
     115<item key="type"><![CDATA[string]]></item> 
     116</dictionary> 
     117</item> 
     118<item type="dictionary"><dictionary> 
     119<item key="id"><![CDATA[recaptchaPublicKey]]></item> 
     120<item key="mandatory" type="int">0</item> 
     121<item key="multilang" type="int">1</item> 
     122<item key="name"><![CDATA[Public Key]]></item> 
     123<item key="repetitive" type="int">0</item> 
     124<item key="type"><![CDATA[string]]></item> 
     125</dictionary> 
     126</item> 
     127<item type="dictionary"><dictionary> 
     128<item key="id"><![CDATA[recaptchaPrivateKey]]></item> 
     129<item key="mandatory" type="int">0</item> 
     130<item key="multilang" type="int">1</item> 
     131<item key="name"><![CDATA[Private Key]]></item> 
    98132<item key="repetitive" type="int">0</item> 
    99133<item key="type"><![CDATA[string]]></item> 
Note: See TracChangeset for help on using the changeset viewer.