Java Code Examples for net.tanesha.recaptcha.ReCaptchaFactory#newReCaptcha()
The following examples show how to use
net.tanesha.recaptcha.ReCaptchaFactory#newReCaptcha() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReCaptchaService.java From attic-rave with Apache License 2.0 | 6 votes |
@Override public String createHtml(HttpServletRequest request) { if (captchaEnabled) { if (StringUtils.isBlank(privateKey) || StringUtils.isBlank(publicKey)) { return invalidConfigurationMessage; } boolean secure = request.isSecure(); ReCaptcha captcha; if (secure) { captcha = ReCaptchaFactory.newSecureReCaptcha(publicKey, privateKey, createNoScript); } else { captcha = ReCaptchaFactory.newReCaptcha(publicKey, privateKey, createNoScript); } return captcha.createRecaptchaHtml(null, null); } return ""; }
Example 2
Source File: ReCaptchaService.java From attic-rave with Apache License 2.0 | 5 votes |
@Override public boolean isValid(HttpServletRequest request) { log.debug("ReCaptcha enabled: {}", captchaEnabled); if (!captchaEnabled) { return true; } if (StringUtils.isBlank(privateKey) || StringUtils.isBlank(publicKey)) { log.error("ReCaptcha service is enabled, however, private or public keys are not defined."); return true; } boolean secure = request.isSecure(); ReCaptcha captcha; if (secure) { captcha = ReCaptchaFactory.newSecureReCaptcha(publicKey, privateKey, createNoScript); } else { captcha = ReCaptchaFactory.newReCaptcha(publicKey, privateKey, createNoScript); } String response = request.getParameter(PARAM_CAPTCHA_RESPONSE); String challenge = request.getParameter(PARAM_CAPTCHA_CHALLENGE); String remoteAddress = request.getRemoteAddr(); // validate: ReCaptchaResponse captchaResponse = captcha.checkAnswer(remoteAddress, challenge, response); boolean valid = captchaResponse.isValid(); if (valid) { return true; } log.warn("Invalid captcha response: {}", captchaResponse.getErrorMessage()); return false; }
Example 3
Source File: UsersAction.java From sakai with Educational Community License v2.0 | 4 votes |
/** * Build the context for the create user mode. */ private String buildCreateContext(SessionState state, Context context) { // put the service in the context context.put("service", userDirectoryService); String blurb = (String) state.getAttribute(CONFIG_CREATE_BLURB); if (!StringUtils.isEmpty(blurb)) { context.put("createBlurb", blurb); } // is the type to be pre-set context.put("type", state.getAttribute("create-type")); boolean isValidatedWithAccountValidator = isValidatedWithAccountValidator(state); boolean isEidEditable = isEidEditable(state); // if the tool is configured to validate through email, we will use AccountValidator to set name fields, etc. So we indicate this in the context to hide fields that are redundant context.put("isValidatedWithAccountValidator", isValidatedWithAccountValidator); // If we're using account validator, an email needs to be sent // If the eid is not editable, the email will be used as the eid context.put("emailRequired", isValidatedWithAccountValidator || !isEidEditable); // password is required when using Gateway New Account tool // attribute "create-user" is true only for New Account tool context.put("pwRequired", state.getAttribute("create-user")); context.put("displayEid", isEidEditable); String value = (String) state.getAttribute("valueEid"); if (value != null) context.put("valueEid", value); value = (String) state.getAttribute("valueFirstName"); if (value != null) context.put("valueFirstName", value); value = (String) state.getAttribute("valueLastName"); if (value != null) context.put("valueLastName", value); value = (String) state.getAttribute("valueEmail"); if (value != null) context.put("valueEmail", value); if ((Boolean)state.getAttribute("user.recaptcha-enabled")) { ReCaptcha captcha = ReCaptchaFactory.newReCaptcha((String)state.getAttribute("user.recaptcha-public-key"), (String)state.getAttribute("user.recaptcha-private-key"), false); String captchaScript = captcha.createRecaptchaHtml((String)state.getAttribute("recaptcha-error"), null); state.removeAttribute("recaptcha-error"); context.put("recaptchaScript", captchaScript); } return "_create"; }
Example 4
Source File: UsersAction.java From sakai with Educational Community License v2.0 | 4 votes |
/** * Build the context for the create user mode. */ private String buildCreateContext(SessionState state, Context context) { // put the service in the context context.put("service", userDirectoryService); String blurb = (String) state.getAttribute(CONFIG_CREATE_BLURB); if (!StringUtils.isEmpty(blurb)) { context.put("createBlurb", blurb); } // is the type to be pre-set context.put("type", state.getAttribute("create-type")); boolean isValidatedWithAccountValidator = isValidatedWithAccountValidator(state); boolean isEidEditable = isEidEditable(state); // if the tool is configured to validate through email, we will use AccountValidator to set name fields, etc. So we indicate this in the context to hide fields that are redundant context.put("isValidatedWithAccountValidator", isValidatedWithAccountValidator); // If we're using account validator, an email needs to be sent // If the eid is not editable, the email will be used as the eid context.put("emailRequired", isValidatedWithAccountValidator || !isEidEditable); // password is required when using Gateway New Account tool // attribute "create-user" is true only for New Account tool context.put("pwRequired", state.getAttribute("create-user")); context.put("displayEid", isEidEditable); String value = (String) state.getAttribute("valueEid"); if (value != null) context.put("valueEid", value); value = (String) state.getAttribute("valueFirstName"); if (value != null) context.put("valueFirstName", value); value = (String) state.getAttribute("valueLastName"); if (value != null) context.put("valueLastName", value); value = (String) state.getAttribute("valueEmail"); if (value != null) context.put("valueEmail", value); if ((Boolean)state.getAttribute("user.recaptcha-enabled")) { ReCaptcha captcha = ReCaptchaFactory.newReCaptcha((String)state.getAttribute("user.recaptcha-public-key"), (String)state.getAttribute("user.recaptcha-private-key"), false); String captchaScript = captcha.createRecaptchaHtml((String)state.getAttribute("recaptcha-error"), null); state.removeAttribute("recaptcha-error"); context.put("recaptchaScript", captchaScript); } return "_create"; }
Example 5
Source File: RecaptchaAction.java From wandora with GNU General Public License v3.0 | 4 votes |
public ReCaptcha makeReCaptcha(){ return ReCaptchaFactory.newReCaptcha(publicKey, privateKey, false); }