You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by da...@cocoon.zones.apache.org on 2006/12/21 12:21:14 UTC

[DAISY] Created: Captcha Widget

A new document has been created.

http://cocoon.zones.apache.org/daisy/documentation/1294.html

Document ID: 1294
Branch: main
Language: default
Name: Captcha Widget
Document Type: Cocoon Document
Created: 12/21/06 11:20:55 AM
Creator (owner): Helma van der Linden
State: draft

Parts
=====

Content
-------
Mime type: text/xml
Size: 2101 bytes
Content:
<html>
<body>

<p>        &lt;!-- generate captcha image --&gt;<br/>
        &lt;map:match pattern="**/captcha-*.jpg"&gt;<br/>
          &lt;map:read type="captcha" src="{session-attr:captcha-{2}}"/&gt;
<br/>
        &lt;/map:match&gt;</p>

<h1>Concept</h1>

<p>To prevent spammers from abusing forms, more and more sites are including an
image that displays a distorted code. This is based on the CAPTCHA technique
(see also the <a href="daisy:686">CAPTCHA</a> block).</p>

<p>The Captcha widget provides a widget containing the generated image and an
input field. The validation is only true if the input in the field matches the
code displayed in the image.<br/>
The widget defines a session attribute with a name of <tt>captcha-&lt;random
id&gt;</tt> and a value containing a random code. The code is also added to a
<tt>secret</tt> attribute of the widget for the validation phase. The image has
the same name as the session attribute with a <tt>jpg</tt> extension.</p>

<h1>Definition</h1>

<p>The definition is simply:</p>

<pre>&lt;fd:captcha id="captchacheck" required="true"&gt;
   &lt;fd:label&gt;&lt;i18n:text&gt;captcha&lt;/i18n:text&gt;&lt;/fd:label&gt;
   &lt;fd:datatype base="string"/&gt;
   &lt;fd:validation&gt;
      &lt;fd:captcha/&gt;
   &lt;/fd:validation&gt;
&lt;/fd:captcha&gt;</pre>

<h2>Sitemap definition</h2>

<p>In your sitemap you need a reference to the
<a href="daisy:687">captchaReader</a>. It is already provided in the standard
Cocoon root sitemap, but if you start from scratch, here it is:</p>

<pre>&lt;map:components&gt;
   ...
   &lt;map:readers ...&gt;
   ...
    &lt;map:reader logger="sitemap.reader.captcha" name="captcha" src="org.apache.cocoon.reading.CaptchaReader"/&gt;
   ...
   &lt;/map:readers&gt;
   ...
&lt;/map:components&gt;
</pre>

<p>You now need to include a pipeline that can generate the CAPTCHA image:</p>

<pre>&lt;!-- generate captcha image --&gt;
&lt;map:match pattern="**/captcha-*.jpg"&gt;
   &lt;map:read type="captcha" src="{session-attr:captcha-{2}}"/&gt;
&lt;/map:match&gt;</pre>

</body>
</html>

Collections
===========
The document belongs to the following collections: documentation