String pageUrl, String challenge, String response,
HttpServletRequest request) {
ConfigEntity config = getBusiness().getConfigBusiness().getConfig();
boolean valid = true;
ReCaptchaResponse recaptchaResponse = null;
if (config.isEnableRecaptcha()) {
recaptchaResponse = RecaptchaUtil.check(
config.getRecaptchaPublicKey(),
config.getRecaptchaPrivateKey(),
challenge, response, request);
valid = recaptchaResponse.isValid();
}
if (valid) {
try {
addComment(ParamUtil.filterXSS(name),
ParamUtil.filterXSS(comment), pageUrl);
return ServiceResponse.createSuccessResponse(
Messages.get("comment_success_create"));
}
catch (ServiceException e) {
return ServiceResponse.createErrorResponse(e.getMessage());
}
}
else {
return ServiceResponse.createErrorResponse(
recaptchaResponse.getErrorMessage());
}
}