Search in sources :

Example 1 with FormBean

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;
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) Signup(uk.nhs.digital.website.beans.Signup) FormBean(com.onehippo.cms7.eforms.hst.beans.FormBean) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with FormBean

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;
}
Also used : AutoDetectFormComponentInfo(com.onehippo.cms7.eforms.hst.components.info.AutoDetectFormComponentInfo) FormBean(com.onehippo.cms7.eforms.hst.beans.FormBean)

Example 3 with 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;
}
Also used : HashMap(java.util.HashMap) ApplicationSecrets(uk.nhs.digital.toolbox.secrets.ApplicationSecrets) MissingResourceException(java.util.MissingResourceException) Resource(org.onehippo.cms7.crisp.api.resource.Resource) ErrorMessage(com.onehippo.cms7.eforms.hst.model.ErrorMessage)

Aggregations

FormBean (com.onehippo.cms7.eforms.hst.beans.FormBean)2 AutoDetectFormComponentInfo (com.onehippo.cms7.eforms.hst.components.info.AutoDetectFormComponentInfo)1 ErrorMessage (com.onehippo.cms7.eforms.hst.model.ErrorMessage)1 HashMap (java.util.HashMap)1 MissingResourceException (java.util.MissingResourceException)1 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 Nullable (org.jetbrains.annotations.Nullable)1 Resource (org.onehippo.cms7.crisp.api.resource.Resource)1 ApplicationSecrets (uk.nhs.digital.toolbox.secrets.ApplicationSecrets)1 Signup (uk.nhs.digital.website.beans.Signup)1