Hello folks,
I have a proposed method for migrating the captcha plugin to a component.
I have posted a patch here:
http://jira.xwiki.org/jira/browse/XWIKI-4741
which contains the core modifications which I am proposing. Though I have
a patch, this is still in the design phase and I welcome anyone to suggest
changes.
ComponentRole: Captcha
/**
* Check if the solution to the captcha is correct.
*
* @param answer The provided solution.
* @return true if the solution is correct.
*/
boolean isAnswerCorrect(String answer);
Implementing components:
DefaultImageCaptchaAction
DefaultSoundCaptchaAction
The new DefaultImageCaptcha component can be used to solve captchas which
were downloaded through the old struts based jcaptcha plugin. Both components
also implement org.xwiki.action.Action and when execute() is called, they
send a captcha to the response.
The components depend on the request and response in the container being
servlet request/response because com.octo.captcha.module.web.image.ImageToJpegHelper
and com.octo.captcha.module.web.sound.SoundToWavHelper require HttpServletRequest and
HttpServletResponse. Also to get the ID of the session in a way that is compatible
with the old struts based method of getting captchas, an HttpServletRequest is needed.
I am not happy with this design as it demands the use of the if instanceof then cast
hack. I would like to hear any ideas about how to clean this up.
There is also a velocity initializer which provides a captcha service with:
/**
* Check if the solution to the captcha is correct.
*
* @param captchaName The name of the Captcha you are checking the answer against
* @param answer The provided solution
* @return true if the solution is correct
* @throws UnsupportedOperationException If there is no captcha by the name
captchaName
*/
public boolean isAnswerCorrect(String captchaName, String answer) throws
UnsupportedOperationException
and
/** @return a List of the names of all registered classes implementing {@link
org.xwiki.captcha.Captcha}. */
public List<String> listCaptchaNames()
In my opinion the html should all be in the application side and the core code
should not even know it's URL. I am working on an application and would be
interested to hear what requirements you think it should meet.
Sorry for the long mail, I am anxious to hear your ideas about this.
Caleb James DeLisle