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:
1 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 
Note: See TracChangeset for help on using the changeset viewer.