Whoops I made a mistake in my example:
How about:
#set($captcha = $captchaservice.getCaptcha("defaultImageCaptcha"))
#set($servletId = $captcha.getServletId($request))
$captcha.isAnswerCorrect($answer)
should be:
$captcha.isAnswerCorrect($servletId, $answer)
Caleb
Caleb James DeLisle wrote:
Asiri Rathnayake wrote:
Hi,
Not exactly, I think you are thinking of:
$captchaservice.isAnswerCorrect($sessionId,
$answer)
Yes. I believe here sessionId is generated by the captcha service for each
captcha displayed? Or is it something else?
I'm asking because recaptcha generates a unque captchaId for each captcha it
generates. Then you need to handover this captchaId + user's answer to the
server to verify the answer.
while captchaName is the hint for getting a
component from the component
manager. eg:
$captchaservice.isAnswerCorrect("defaultImageCaptcha", $answer)
Ok, I understand now.
The fact that the last call to the struts based
jcaptcha component was from
same session
means that the answer provided will work.
Perhaps it would be best to offer a way to check the answer with the
sessionId
either A:
$captchaservice.isAnswerCorrect("defaultImageCaptcha", $sessionId, $answer)
or B:
#set($captcha = $captchaservice.getCaptcha("defaultImageCaptcha"))
$captcha.isAnswerCorrect($sessionId, $answer)
Both sounds good. Although I like the second form.
Agreed, I am thinking I can create an implementation of Captcha which wraps
another implementation but never throws any exceptions so it is velocity friendly.
Also an easy way to get the session id using
$request in Velocity?
Something like:
A:
#set($sessionId = $captchaservice.getSessionId($request))
or B:
#set($sessionId = $captcha.getSessionId($request))
I don't know whether binding velocity APIs to HTTPRequest is a good idea,
but it will surely make things easy. We could even have something like:
#set($captcha = $captchaservice.getCaptcha("defaultImageCaptcha"))
$captcha.isAnswerCorrect($request)
So we leave all the parameter resolution to the captcha component itself.
As easy as it is, I get nervous thinking about hardcoding the name of the
parameter in the core, suppose we wanted to use it in a case where that
parameter was taken? Anyway defining hardcoded strings gives me a bad feeling.
How about:
#set($captcha = $captchaservice.getCaptcha("defaultImageCaptcha"))
#set($servletId = $captcha.getServletId($request))
$captcha.isAnswerCorrect($answer)
captcha.getServletId can take an HttpServletRequest object and the XWikiRequest
(in velocity that is $request) will work because XWikiRequest extends and wraps
the HttpServletRequest object.
Thanks,
Caleb
Thanks.
- Asiri
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs