You are here: Home CS-Workshop CS-Workshop Blog

CS-Workshop Blog

Using collective.captcha in custom forms

by Mikel Larreategi — last modified Jan 27, 2009 11:25 AM
Filed Under:

collective.captcha provides a simple way to create and verify captcha image and sounds to protect your forms from spambots.

We are using Plone for some community sites with blogs and newsitems with comments and we were attacked by spambots and found ourselves writing spam-deleting scripts until we found collective.captcha.

collective.captcha provides a very simple browser view to generate captcha images (and also sound-captchas) and to verify user input. We are using it in Plone 2.5.x and also in 3.x (like in this blog) and it works great in both of them.

First of all, you need to include in your buildout, both in eggs and zcml sections of your instance and then run the buildout to get it installed.

Then you need to integrate the captcha generated image and the form to get user input, we use a simple page template for that, called captcha_widget with the following content:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
i18n:domain="ataria">

<body>

<span metal:define-macro="captcha">

<div class="field"
tal:define="error errors/captcha|nothing;"
tal:attributes="class python:test(error, 'field error', 'field')">
<label for="captcha" i18n:translate="label_captcha">Captcha</label>

<span class="fieldRequired" title="Required"
i18n:attributes="title"
i18n:domain="plone"
i18n:translate="label_required">(Required)</span>

<div class="formHelp" i18n:translate="help_captcha">
Provide the text in the image. Just to avoid spambots
</div>
<p tal:replace="structure here/@@captcha/image_tag" />

<div>
<input type="text"
name="captcha"
id="captcha"
value="" />
</div>
</div>

</span>

</body>
</html>

The relevant part in this page template is the line in which the captcha image is rendered:

<p tal:replace="structure here/@@captcha/image_tag" />

The first part is completed. Now we just have to check that the user input and the string shown in the captcha are the same. We mainly use collective.captcha together with qPloneComments and we use CMFFormController based forms so we need to create the .cpt with the form in which we include the captcha with the following sentence:

<metal:captcha use-macro="here/captcha_widget/macros/captcha" />

After that you have to write the validator script and tie together with the .metadata file of your form. The script we use is this:

from Products.CMFPlone import PloneMessageFactory as _

captcha = context.REQUEST.get('captcha')

view = context.restrictedTraverse('@@captcha')

if not view.verify(captcha):
state.setError('captcha', _(u'Are you a bot? Try again...'))
state.set(status='failure')

return state

With this, you will have your form protected from spambots.

But collective.captcha has some sort of bug (or at least it has a bug with our configuration) in which zope can't start if you do not override the captcha view in your product. We reported the error in plone-users but had no input about it, so I just reproduce it here.

To get collective.captcha work correctly and zope start, you have to add an overrides.zcml file to your product and add the following ZCML snippet in it:

<browser:page
name="captcha"
for="*"
permission="zope2.Public"
allowed_interface="collective.captcha.browser.interfaces.ICaptchaView"
class="collective.captcha.browser.captcha.Captcha"
/>

So now you know how to protect your hand-made plone forms with collective.captcha.

I can't reorder elements in a Plone folder!

by Mikel Larreategi — last modified Nov 11, 2008 05:25 PM
Filed Under:

Recently I had a problem in a website we are currently developing to reorder some custom content-types in Plone folder.

We are currently building a website that has many customized content-types. In the main folder of the structure we are building, the client wants to reorder elements freely, like in a normal Plone folder. Well, the main folder of the structure is currently a Plone folder, so "no problem" I said, just go to Contents tabs and reorder the elements. But... aghh !!! I couldn't reorder the items !!

I started investigating what was going on, putting a pdb here and there, and found a curious thing: the items stored in the folder were some archetypes based custom objects with a portal type with a space in its name. This portal type was "Product Line". The reordering code compared the items inside it and checked whether the item was actually in it looking at its _objects attribute, nothing special til here. But the check was not safe enough.

The code looked at the Metatype of the FTIs in the portal_types tool to check whether the element which was being reordered was currently a CMF object. But the Metatype of the FTI wasn't the same as the meta type of the object, because the Metatype of the FTI was the actual portal type of the object.

Moreover, the _objects attribute wasn't modified when the meta type of the object was changed, so it wasn't enough the change just the meta_type. I had to write a migration script to change the _objects attribute of the folder to change "ProductLine" with "Product Line". That change made my custom objects orderable.

 

World Plone Day in the Basque Country

by Luistxo Fernandez — last modified Nov 07, 2008 10:20 AM
Filed Under:

Our company office space hosts today the World Plone Day.

World Plone Day is happening today in over 30 cities around the world. We organised a local meeting in the Basque Country, and talks and mini-workshops are happening around me just as I write these lines.


Argazkiak.org | World Plone Day 2008 © cc-by-sa: codesyntax

Some 30 people gathered here today, and we are happy to see webmasters that edit some of the Plone websites that CodeSyntax developed.


Argazkiak.org | Oier, Joxe, Iban © cc-by-sa: codesyntax

Above, editors of community website Dantzan.com, Oier Araolaza; from Mondragon University, Joxe Aranzabal; and from local newssite Goiena.net, Iban Arantzabal.

One of our customers also volunteered to talk. Jabier Santamaria is the engineer behind a Plonegov / Udalplone (our local brand for this Plone project to create websites for the public administration) website, the one for the town council of Amorebieta-Etxano.


Argazkiak.org | Jabier Santamaria © cc-by-sa: codesyntax

We've been happy to welcome as well other Plone creators in the Basque Country, not only sites developed by us. Jesus Romo, of the virtual campus of the University of the Basque Country, has explained how they use Plone in their eKasi elearning project.


Argazkiak.org | Jesus Romo, EHU © cc-by-sa: codesyntax

More pictures from this day in Flickr. And the slides from the presentations made by CodeSyntax coworkers today.

Open Source World Conference Malaga 2008

by Eneko Astigarraga — last modified Oct 20, 2008 09:30 AM
Filed Under:

We are taking part in the Open Source World Conference that will be held at the Malaga's Trade Fairs and Congress Center on 20-22 October.  A great Conference, more than 8,000 people are expected to attend to the conference, the exhibition and complementary activities area is to extend to over 6500 m² and with world-level open source software communities participation.

I hope to attend to some events in which we participate.

 

OSOR, Open Source Observatory

Observatorio Software Libre OSOR

On Monday is the OSOR, Open Source Observatory and Repository for European Public Administrations  Launch Event at the Open Source World Conference.

The OSOR is a platform actively supporting the sharing of OSS-based eGovernment applications and experiences across Europe, and PloneGov project is a best practice example in the area. Xavier Heymans, ZEA Partners, presents the PloneGov initiative.

 

Morfeo project

Morfeo project and community is collaborating with a stand and 8 Morfeo-related taMorfeolks and workshops.

Morfeo community is a well open innovation model, and tomorrow you have a interesting speech about  "MORFEO: the development of open source software as part of the strategy for materializing the future Internet of Services" or the Miguel Ángel Cañas and Marcos Reyes speech about EzWeb platform: "EzWeb: an open source application mashup web platform for the next-generation SOA and the future Internet of Services"

 

Morfeo Project Malaga

 

Plone everywhere

Btw, I'm talking about  PloneGov , our e-government solution, but Plone is everywhere present in Malaga: for example, the Open Source World Conference site (1) and the OSOR open source observatory (2) are developped  on Plone, our main CMS choice, based on Zope and Python, That's a great choice! 

Welcome Plone Conference 2008

by Mikel Larreategi — last modified Oct 08, 2008 08:31 PM
Filed Under:

We landed in the USA yesterday afternoon, after a long-long trip from Eibar. Now we are waiting for the afternoon talks to be started. Welcome !

We managed to come to the Ronald Reagan Center at 9:00 more or less, got our registration badges and switched on the laptop... but the wifi was down in the main hall... That's the only bug we found in the Conference.

The Conference has started with the logistics information and the Keynote by Alex Limi and Alan Runyan.

Well, we are just recovering from the lunch (mmm, excellent sandwitch!) and waiting for the next talk about Plone 3.1 product migration to start.

More to come later... with photos if we get a stable net conection and upload some photos to Flickr.

Weblog Authors

Eneko Astigarraga

Eneko Astigarraga

Mikel Larreategi

Location: Eibar
Mikel Larreategi

Gari Araolaza

Location: Eibar, ES
Gari Araolaza

Luistxo Fernandez

Location: Eibar
Luistxo Fernandez