Changeset 315
- Timestamp:
- 26.11.2008 10:45:44 (3 years ago)
- Location:
- CMESS/forum/branches/captcha/cmess
- Files:
-
- 3 edited
- 1 moved
-
. (moved) (moved from CMESS/forum/branches/captcha/org/cmess)
-
forum/c_captcha_basic.py (modified) (2 diffs)
-
forum/c_handler_captcha.py (modified) (2 diffs)
-
forum/zms/zmsforum.metaobj.xml (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CMESS/forum/branches/captcha/cmess/forum/c_captcha_basic.py
r305 r315 1 from org.cmess.forum.CaptchasDotNet import CaptchasDotNet1 from com.zms.captcha.CaptchasDotNet import CaptchasDotNet 2 2 3 3 class C_Captcha_Basic: … … 17 17 18 18 class 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()) 22 30 23 31 def GetContent(self): 24 32 temp_result = '<input type="hidden" name="captcha_random" value="%s" />'%self.captcha.random() 25 33 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) 28 36 temp_result += '<input type="text" name="captcha_password" size="16" />' 29 37 30 38 return temp_result 31 39 32 def IsCodeValid(self , REQUEST):40 def IsCodeValid(self): 33 41 #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', ''))): 35 43 #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, '') 38 46 else: 39 temp_result = (False, 'You entered the wrong password.')47 temp_result = (False, self.zms_context.getLangStr('captchaWrongVerification', self.zms_lang)) 40 48 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)) 42 50 43 51 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_Basic2 from org.cmess.forum.c_captcha_basic import C_Captcha_Dot_Net1 from com.zms.captcha.c_captcha_basic import C_Captcha_Basic 2 from com.zms.captcha.c_captcha_basic import C_Captcha_Dot_Net 3 3 4 4 class 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 11 13 12 14 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() 15 17 else: 16 18 temp_result = '' … … 18 20 return temp_result 19 21 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() 23 25 else: 24 26 temp_result = False 25 27 26 28 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 94 94 </item> 95 95 <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> 106 102 </dictionary> 107 103 </item> … … 1210 1206 1211 1207 def 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: 1216 1215 temp_result = (True, '') 1217 1216 … … 1245 1244 1246 1245 def 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: 1251 1253 temp_captcha_content = '' 1252 1254 1253 1255 return temp_captcha_content 1254 1256 … … 2231 2233 </dictionary> 2232 2234 </item> 2233 <item type="dictionary"><dictionary>2234 <item key="custom"><![CDATA[from org.cmess.forum.c_handler_captcha import C_Handler_Captcha2235 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_Captcha2251 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>2265 2235 </list> 2266 2236 </item>
Note: See TracChangeset
for help on using the changeset viewer.
