use of com.onehippo.cms7.eforms.hst.beans.FormBean in project hippo by NHS-digital-website.
the class CustomAutoDetectFormComponent method getFormBeanFromSignupDocument.
@Nullable
private FormBean getFormBeanFromSignupDocument(final HstRequest request) {
final HippoBean document = request.getRequestContext().getContentBean();
if (document instanceof Signup) {
final Signup signupDocument = (Signup) document;
return (FormBean) signupDocument.getFormLink().getLink();
}
if (document == null || !document.isHippoDocumentBean() || !(document instanceof FormBean)) {
if (log.isDebugEnabled()) {
log.warn("*** EFORMS ***");
log.warn("Cannot get the form bean, returning null. Reason: the content bean is null or it does not match the FormBean type [eforms:form].");
log.warn("Override the method [BaseEformComponent#getFormBean(HstRequest)] to get the form bean in a different way, e.g. from a linked bean.");
log.warn("Will attempt to get the form bean from the component picker.");
log.warn("*** EFORMS ***");
}
return null;
}
return (FormBean) document;
}
use of com.onehippo.cms7.eforms.hst.beans.FormBean in project hippo by NHS-digital-website.
the class CustomAutoDetectFormComponent method getFormBeanFromPicker.
private FormBean getFormBeanFromPicker(final HstRequest request) {
final AutoDetectFormComponentInfo paramsInfo = getComponentParametersInfo(request);
final String formDocPath = paramsInfo.getForm();
FormBean formBean = getFormBeanFromPath(request, formDocPath);
if (formBean == null) {
formBean = super.getFormBean(request);
}
return formBean;
}
use of com.onehippo.cms7.eforms.hst.beans.FormBean in project hippo by NHS-digital-website.
the class ReCaptchaValidationPlugin method validate.
@Override
public Map<String, ErrorMessage> validate(HstRequest request, HstResponse response, ComponentConfiguration config, FormBean bean, Form form, FormMap map) {
final String reCaptchaSiteKey = ((ApplicationSecrets) getComponentManager().getComponent("applicationSecrets")).getValue("GOOGLE_CAPTCHA_SITE_KEY");
final String reCaptchaSecretKey = ((ApplicationSecrets) getComponentManager().getComponent("applicationSecrets")).getValue("GOOGLE_CAPTCHA_SECRET");
final Map<String, ErrorMessage> errors = new HashMap<>();
final String clientReCaptchaResponseString = request.getParameter("gRecaptchaResponse");
if (map.getFormMap().size() == 0 || clientReCaptchaResponseString == null && "RENDER_PHASE".equals(request.getLifecyclePhase()) && map.getFormMap().get("eforms_process_done") != null) {
return errors;
}
try {
// to validate response with Google ReCaptcha API
log.debug("***************************** Validate ReCaptcha *****************************");
log.debug("Recaptcha Site Key: " + reCaptchaSiteKey);
log.debug("Recaptcha Secret Key: " + ApplicationSecrets.mask(reCaptchaSecretKey));
log.debug("Recaptcha Response: " + clientReCaptchaResponseString);
Resource gRecaptchaResponse = validateReCaptcha(clientReCaptchaResponseString, reCaptchaSecretKey);
if (gRecaptchaResponse != null) {
if ((boolean) gRecaptchaResponse.getValue("success")) {
log.debug("ReCaptcha succeeded!");
log.debug("ReCaptcha Challenge TTL: " + gRecaptchaResponse.getValue("challenge_ts"));
log.debug("ReCaptcha Hostname: " + gRecaptchaResponse.getValue("hostname"));
} else {
String errorList = getReCaptchaErrors(gRecaptchaResponse);
log.debug("ReCaptcha Failed:" + errorList);
errors.put("ReCaptcha Validation", new ErrorMessage("ReCaptcha validation failed", errorList));
}
}
} catch (MissingResourceException e) {
log.warn(e.getMessage(), e.getClassName(), e.getKey(), e);
}
log.debug("ReCaptcha Error count is: " + errors.size());
log.debug("**************************** End Validate ReCaptcha ****************************");
return errors;
}
Aggregations