留言板
Captcha On liferay 6.0.6
Hi all , I don't if this is the right place to ask about captcha, Correct me if I'm Wrong,
I've followed Captcha Liferay
but my captcha won't validate,, here's the code i'm writing I'm still confuse
I'm manage to show the captcha but i can validate it
and this is my code for my action
what should i do? if i've code like that??
I've Tried with this
but when i'm trying to submit it's show
what's wrong with my code??
thank's
Regards
Danial
I've followed Captcha Liferay
but my captcha won't validate,, here's the code i'm writing I'm still confuse
I'm manage to show the captcha but i can validate it
private void checkCaptcha(PortletRequest request)throws Exception
{
String enteredCaptchaText = ParamUtil.getString(request, "captchaText");
PortletSession session = request.getPortletSession();
String captchaText = getCaptchaValueFromSession(session);
if (Validator.isNull(captchaText)) {
throw new Exception("Internal Error! Captcha text not found in session");
}
if (!captchaText.equalsIgnoreCase(enteredCaptchaText)) {
throw new Exception("Invalid captcha text. Please reenter.");
}
}
private String getCaptchaValueFromSession(PortletSession session) {
Enumeration<string> atNames = session.getAttributeNames();
while (atNames.hasMoreElements()) {
String name = atNames.nextElement();
if (name.contains("CAPTCHA_TEXT")) {
return (String) session.getAttribute(name);
}
}
return null;
}</string>
and this is my code for my action
public void addPendaftar(ActionRequest request, ActionResponse response)
throws PortalException, SystemException {
Pendaftaran pendaftar = ActionUtil.pendaftaranFromRequest(request);
ArrayList<string> errors = new ArrayList<string>();
ServiceContext serviceContext = ServiceContextFactory.getInstance(
Pendaftaran.class.getName(), request);
log.info("masuk");
if (PdValidator.validatePendaftar(pendaftar, errors)) {
log.info("berhasil");
try {
PendaftaranLocalServiceUtil.addPendaftaran(pendaftar,
pendaftar.getUserId(), serviceContext);
} catch (SystemException e) {
errors.add("failed-to-add");
} catch (PortalException e) {
errors.add("failed-to-add");
}
request.setAttribute("pendaftaran", pendaftar);
response.setRenderParameter("jspPage", FileJSP);
} else
{
for (String error : errors) {
SessionErrors.add(request, error);
}
}
}
</string></string>
what should i do? if i've code like that??
I've Tried with this
log.info("masuk");
if (PdValidator.validatePendaftar(pendaftar, errors)&&checkCaptcha(request)) {
log.info("berhasil");
try {
PendaftaranLocalServiceUtil.addPendaftaran(pendaftar,
pendaftar.getUserId(), serviceContext);
but when i'm trying to submit it's show
Internal Error! Captcha text not found in session
what's wrong with my code??
thank's
Regards
Danial