Changeset 315


Ignore:
Timestamp:
26.11.2008 10:45:44 (3 years ago)
Author:
mike
Message:

zms forum uses captchas to verify human interaction

Location:
CMESS/forum/branches/captcha/cmess
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • CMESS/forum/branches/captcha/cmess/forum/c_captcha_basic.py

    r305 r315  
    1 from org.cmess.forum.CaptchasDotNet import CaptchasDotNet 
     1from com.zms.captcha.CaptchasDotNet import CaptchasDotNet 
    22 
    33class C_Captcha_Basic: 
     
    1717 
    1818class C_Captcha_Dot_Net(C_Captcha_Basic): 
    19         def __init__(self): 
    20                 self.id                         = 'captcha.net' 
    21                 self.captcha    = CaptchasDotNet(client = 'demo', secret = 'secret') 
     19        def __init__(self, zms_context): 
     20                temp_client             = zms_context.attr_captcha.getObjProperty('captchaClient', zms_context.REQUEST) 
     21                temp_secret             = zms_context.attr_captcha.getObjProperty('captchaSecret', zms_context.REQUEST) 
     22                 
     23                temp_chars              = 'abcdefghkmnopqrstuvwxyz' 
     24                temp_chars              += (temp_client != 'demo') and temp_chars.upper() + '0123456789' or '' 
     25                 
     26                self.id                                         = 'captcha.net' 
     27                self.captcha                    = CaptchasDotNet(temp_client, temp_secret, alphabet = temp_chars) 
     28                self.zms_context        = zms_context 
     29                self.zms_lang                   = self.zms_context.REQUEST.get('lang', self.zms_context.getPrimaryLanguage()) 
    2230                 
    2331        def GetContent(self): 
    2432                temp_result = '<input type="hidden" name="captcha_random" value="%s" />'%self.captcha.random() 
    2533                temp_result += self.captcha.image() + '<br />'  
    26                 temp_result += '<input type="submit" name="captcha_new" value="get new image" /><br />' 
    27                 temp_result += '<label>Please enter the shown characters</label><br />' 
     34                temp_result += '<input type="submit" name="captcha_new" value="%s" /><br />'%self.zms_context.getLangStr('captchaNewCode', self.zms_lang) 
     35                temp_result += '<label>%s</label><br />'%self.zms_context.getLangStr('captchaLabel', self.zms_lang) 
    2836                temp_result += '<input type="text" name="captcha_password" size="16" />' 
    2937                 
    3038                return temp_result 
    3139         
    32         def IsCodeValid(self, REQUEST): 
     40        def IsCodeValid(self): 
    3341                #check random string 
    34                 if (self.captcha.validate(REQUEST.form.get('captcha_random', ''))): 
     42                if (self.captcha.validate(self.zms_context.REQUEST.form.get('captcha_random', ''))): 
    3543                        #check captcha password 
    36                         if (self.captcha.verify(REQUEST.form.get('captcha_password', ''))): 
    37                                 temp_result = (True, 'correct password') 
     44                        if (self.captcha.verify(self.zms_context.REQUEST.form.get('captcha_password', ''))): 
     45                                temp_result = (True, '') 
    3846                        else: 
    39                                 temp_result = (False, 'You entered the wrong password.') 
     47                                temp_result = (False, self.zms_context.getLangStr('captchaWrongVerification', self.zms_lang)) 
    4048                else: 
    41                         temp_result = (False, 'Every CAPTCHA can only be used once. The current CAPTCHA has already been used. Try again.') 
     49                        temp_result = (False, self.zms_context.getLangStr('captchaInvalid', self.zms_lang)) 
    4250                         
    4351                return temp_result 
  • CMESS/forum/branches/captcha/cmess/forum/c_handler_captcha.py

    r305 r315  
    1 from org.cmess.forum.c_captcha_basic import C_Captcha_Basic 
    2 from org.cmess.forum.c_captcha_basic import C_Captcha_Dot_Net 
     1from com.zms.captcha.c_captcha_basic import C_Captcha_Basic 
     2from com.zms.captcha.c_captcha_basic import C_Captcha_Dot_Net 
    33 
    44class C_Handler_Captcha: 
    5         def __init__(self, mode): 
    6                 self.captcha_mode = mode 
    7                 self.obj_dict = {} 
    8                  
    9                 temp_obj = C_Captcha_Dot_Net() 
    10                 self.RegisterCaptchaObj(temp_obj.GetID(), temp_obj) 
     5        def __init__(self, zms_context): 
     6                try: 
     7                        if (zms_context.attr_captcha.getObjProperty('captchaService', zms_context.REQUEST) == 'captcha.net'): 
     8                                self.captcha_obj = C_Captcha_Dot_Net(zms_context) 
     9                        else: 
     10                                self.captcha_obj = None 
     11                except: 
     12                        self.captcha_obj = None 
    1113                 
    1214        def GetCaptchaContent(self): 
    13                 if (self.obj_dict.has_key(self.captcha_mode)): 
    14                         temp_result = self.obj_dict[self.captcha_mode].GetContent() 
     15                if (self.captcha_obj is not None): 
     16                        temp_result = self.captcha_obj.GetContent() 
    1517                else: 
    1618                        temp_result = '' 
     
    1820                return temp_result 
    1921         
    20         def IsCodeValid(self, REQUEST): 
    21                 if (self.obj_dict.has_key(self.captcha_mode)): 
    22                         temp_result = self.obj_dict[self.captcha_mode].IsCodeValid(REQUEST) 
     22        def IsCodeValid(self): 
     23                if (self.captcha_obj is not None): 
     24                        temp_result = self.captcha_obj.IsCodeValid() 
    2325                else: 
    2426                        temp_result = False 
    2527                 
    2628                return temp_result 
    27          
    28         def RegisterCaptchaObj(self, id, obj): 
    29                 if (obj is not None and isinstance(obj, C_Captcha_Basic)): 
    30                         if (self.obj_dict.has_key(id)): 
    31                                 self.obj_dict.update({id : obj}) 
    32                         else: 
    33                                 self.obj_dict[id] = obj 
  • CMESS/forum/branches/captcha/cmess/forum/zms/zmsforum.metaobj.xml

    r304 r315  
    9494</item> 
    9595<item type="dictionary"><dictionary> 
    96 <item key="id"><![CDATA[zfEnableCaptcha]]></item> 
    97 <item key="keys" type="list"><list> 
    98 <item><![CDATA[captcha.net]]></item> 
    99 </list> 
    100 </item> 
    101 <item key="mandatory" type="int">0</item> 
    102 <item key="multilang" type="int">1</item> 
    103 <item key="name"><![CDATA[Captcha?]]></item> 
    104 <item key="repetitive" type="int">0</item> 
    105 <item key="type"><![CDATA[select]]></item> 
     96<item key="id"><![CDATA[attr_captcha]]></item> 
     97<item key="mandatory" type="int">1</item> 
     98<item key="multilang" type="int">0</item> 
     99<item key="name"><![CDATA[Captcha]]></item> 
     100<item key="repetitive" type="int">0</item> 
     101<item key="type"><![CDATA[attr_captcha]]></item> 
    106102</dictionary> 
    107103</item> 
     
    12101206 
    12111207def checkCaptcha(): 
    1212         temp_captcha_mode = context.getObjProperty('zfEnableCaptcha', REQUEST) 
    1213         if ((temp_captcha_mode is not None) and (len(temp_captcha_mode) > 0)): 
    1214                 temp_result = context.ZMSForum_isCaptchaValid(temp_captcha_mode, REQUEST) 
    1215         else: 
     1208        try: 
     1209                temp_captcha_enabled = context.attr_captcha.getObjProperty('captchaEnabled', REQUEST) 
     1210                if (temp_captcha_enabled): 
     1211                        temp_result = context.captcha_isValid(context) 
     1212                else: 
     1213                        temp_result = (True, '') 
     1214        except: 
    12161215                temp_result = (True, '') 
    12171216                 
     
    12451244 
    12461245def getCaptchaContent(): 
    1247         temp_captcha_mode = context.getObjProperty('zfEnableCaptcha', REQUEST) 
    1248         if ((temp_captcha_mode is not None) and (len(temp_captcha_mode) > 0)): 
    1249                 temp_captcha_content = context.ZMSForum_getCaptchaContent(temp_captcha_mode) 
    1250         else: 
     1246        try: 
     1247                temp_captcha_enabled = context.attr_captcha.getObjProperty('captchaEnabled', REQUEST) 
     1248                if (temp_captcha_enabled): 
     1249                        temp_captcha_content = context.captcha_getContent(context) 
     1250                else: 
     1251                        temp_captcha_content = '' 
     1252        except: 
    12511253                temp_captcha_content = '' 
    1252                  
     1254         
    12531255        return temp_captcha_content 
    12541256 
     
    22312233</dictionary> 
    22322234</item> 
    2233 <item type="dictionary"><dictionary> 
    2234 <item key="custom"><![CDATA[from org.cmess.forum.c_handler_captcha import C_Handler_Captcha  
    2235  
    2236 def ZMSForum_getCaptchaContent(captcha_mode): 
    2237   temp_handler = C_Handler_Captcha(captcha_mode) 
    2238   temp_result = temp_handler.GetCaptchaContent() 
    2239    
    2240   return temp_result]]></item> 
    2241 <item key="id"><![CDATA[ZMSForum_getCaptchaContent]]></item> 
    2242 <item key="mandatory" type="int">0</item> 
    2243 <item key="multilang" type="int">0</item> 
    2244 <item key="name"><![CDATA[ZMSForum_getCaptchaContent]]></item> 
    2245 <item key="repetitive" type="int">0</item> 
    2246 <item key="type"><![CDATA[External Method]]></item> 
    2247 </dictionary> 
    2248 </item> 
    2249 <item type="dictionary"><dictionary> 
    2250 <item key="custom"><![CDATA[from org.cmess.forum.c_handler_captcha import C_Handler_Captcha  
    2251  
    2252 def ZMSForum_isCaptchaValid(captcha_mode, REQUEST): 
    2253   temp_handler = C_Handler_Captcha(captcha_mode) 
    2254   temp_result = temp_handler.IsCodeValid(REQUEST) 
    2255    
    2256   return temp_result]]></item> 
    2257 <item key="id"><![CDATA[ZMSForum_isCaptchaValid]]></item> 
    2258 <item key="mandatory" type="int">0</item> 
    2259 <item key="multilang" type="int">0</item> 
    2260 <item key="name"><![CDATA[ZMSForum_isCaptchaValid]]></item> 
    2261 <item key="repetitive" type="int">0</item> 
    2262 <item key="type"><![CDATA[External Method]]></item> 
    2263 </dictionary> 
    2264 </item> 
    22652235</list> 
    22662236</item> 
Note: See TracChangeset for help on using the changeset viewer.