Changeset 8415 for main/waeup.kofa/trunk


Ignore:
Timestamp:
11 May 2012, 06:30:36 (13 years ago)
Author:
Henrik Bettermann
Message:

Add captcha.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/browser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r8367 r8415  
    260260
    261261class EnquiriesForm(ContactAdminForm):
     262    """Captcha'd page to let anonymous send emails to the administrator.
     263    """
    262264    grok.name('enquiries')
    263265    grok.require('waeup.Public')
     
    266268                          'fullname', 'email_from', 'body')
    267269
     270    def update(self):
     271        # Handle captcha
     272        self.captcha = getUtility(ICaptchaManager).getCaptcha()
     273        self.captcha_result = self.captcha.verify(self.request)
     274        self.captcha_code = self.captcha.display(self.captcha_result.error_code)
     275        return super(EnquiriesForm, self).update()
     276
    268277    @action(_('Send now'), style='primary')
    269278    def send(self, *args, **data):
     279        if not self.captcha_result.is_valid:
     280            # Captcha will display error messages automatically.
     281            # No need to flash something.
     282            return
    270283        kofa_utils = getUtility(IKofaUtils)
    271284        success = kofa_utils.sendContactForm(
     
    480493        self.widgets['title'].displayWidth = 30
    481494        self.widgets['description'].height = 3
     495        return
    482496
    483497    @action(_('Save'), style='primary')
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/contactform.pt

    r8078 r8415  
    1818  </tal:block>
    1919
    20   <div tal:condition="view/availableActions">
    21     <input tal:repeat="action view/actions"
    22            tal:replace="structure action/render"
    23            />
    24   </div>
     20  <tal:captcha condition="view/captcha_code|nothing">
     21    <p tal:content="structure view/captcha_code"></p>
     22    <p i18n:translate="">
     23      Please solve the captcha to prevent misuse of this service.
     24    </p>
     25  </tal:captcha>
     26
     27    <div tal:condition="view/availableActions">
     28      <input tal:repeat="action view/actions"
     29             tal:replace="structure action/render"
     30             />
     31    </div>
    2532</form>
Note: See TracChangeset for help on using the changeset viewer.