本文整理汇总了Java中net.tanesha.recaptcha.ReCaptchaFactory.newSecureReCaptcha方法的典型用法代码示例。如果您正苦于以下问题:Java ReCaptchaFactory.newSecureReCaptcha方法的具体用法?Java ReCaptchaFactory.newSecureReCaptcha怎么用?Java ReCaptchaFactory.newSecureReCaptcha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.tanesha.recaptcha.ReCaptchaFactory
的用法示例。
在下文中一共展示了ReCaptchaFactory.newSecureReCaptcha方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHtml
import net.tanesha.recaptcha.ReCaptchaFactory; //导入方法依赖的package包/类
@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 "";
}
示例2: recover
import net.tanesha.recaptcha.ReCaptchaFactory; //导入方法依赖的package包/类
@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String usernameOrEmail = StringUtils.trimToNull(request.getParameter("usernameOrEmail"));
ReCaptcha captcha = ReCaptchaFactory.newSecureReCaptcha("6LcZ3OMSAAAAANkKMdFdaNopWu9iS03V-nLOuoiH",
"6LcZ3OMSAAAAAPaFg89mEzs-Ft0fIu7wxfKtkwmQ", false);
boolean showCaptcha = true;
if (usernameOrEmail != null) {
map.put("usernameOrEmail", usernameOrEmail);
User user = getUserByUsernameOrEmail(usernameOrEmail);
String challenge = request.getParameter("recaptcha_challenge_field");
String uresponse = request.getParameter("recaptcha_response_field");
ReCaptchaResponse captchaResponse = captcha.checkAnswer(request.getRemoteAddr(), challenge, uresponse);
if (!captchaResponse.isValid()) {
map.put("error", "recover.error.invalidcaptcha");
} else if (user == null) {
map.put("error", "recover.error.usernotfound");
} else if (user.getEmail() == null) {
map.put("error", "recover.error.noemail");
} else {
String password = RandomStringUtils.randomAlphanumeric(8);
if (emailPassword(password, user.getUsername(), user.getEmail())) {
map.put("sentTo", user.getEmail());
user.setLdapAuthenticated(false);
user.setPassword(password);
securityService.updateUser(user);
showCaptcha = false;
} else {
map.put("error", "recover.error.sendfailed");
}
}
}
if (showCaptcha) {
map.put("captcha", captcha.createRecaptchaHtml(null, null));
}
return new ModelAndView("recover", "model", map);
}
示例3: isValid
import net.tanesha.recaptcha.ReCaptchaFactory; //导入方法依赖的package包/类
@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;
}
示例4: createCaptchaHtml
import net.tanesha.recaptcha.ReCaptchaFactory; //导入方法依赖的package包/类
public String createCaptchaHtml() {
if (config.hasCaptchaKeys()) {
ReCaptcha reCaptcha = ReCaptchaFactory.newSecureReCaptcha(config.reCaptchaPublicKey(), config.reCaptchaPrivateKey(), false);
return reCaptcha.createRecaptchaHtml(null, null);
}
return "";
}
示例5: getReCaptchaHtml
import net.tanesha.recaptcha.ReCaptchaFactory; //导入方法依赖的package包/类
public String getReCaptchaHtml() {
if (!useReCaptcha()) {
return "";
}
ReCaptcha c = ReCaptchaFactory.newSecureReCaptcha(
properties.getRecaptchaPublic(), properties.getRecaptchaPrivate(), false);
return c.createRecaptchaHtml(null, null);
}
示例6: recover
import net.tanesha.recaptcha.ReCaptchaFactory; //导入方法依赖的package包/类
public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String usernameOrEmail = StringUtils.trimToNull(request.getParameter("usernameOrEmail"));
ReCaptcha captcha = ReCaptchaFactory.newSecureReCaptcha("6LcZ3OMSAAAAANkKMdFdaNopWu9iS03V-nLOuoiH",
"6LcZ3OMSAAAAAPaFg89mEzs-Ft0fIu7wxfKtkwmQ", false);
boolean showCaptcha = true;
if (usernameOrEmail != null) {
map.put("usernameOrEmail", usernameOrEmail);
User user = getUserByUsernameOrEmail(usernameOrEmail);
String challenge = request.getParameter("recaptcha_challenge_field");
String uresponse = request.getParameter("recaptcha_response_field");
ReCaptchaResponse captchaResponse = captcha.checkAnswer(request.getRemoteAddr(), challenge, uresponse);
if (!captchaResponse.isValid()) {
map.put("error", "recover.error.invalidcaptcha");
} else if (user == null) {
map.put("error", "recover.error.usernotfound");
} else if (user.getEmail() == null) {
map.put("error", "recover.error.noemail");
} else {
String password = RandomStringUtils.randomAlphanumeric(8);
if (emailPassword(password, user.getUsername(), user.getEmail())) {
map.put("sentTo", user.getEmail());
user.setLdapAuthenticated(false);
user.setPassword(password);
securityService.updateUser(user);
showCaptcha = false;
} else {
map.put("error", "recover.error.sendfailed");
}
}
}
if (showCaptcha) {
map.put("captcha", captcha.createRecaptchaHtml(null, null));
}
return new ModelAndView("recover", "model", map);
}
示例7: recover
import net.tanesha.recaptcha.ReCaptchaFactory; //导入方法依赖的package包/类
public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String usernameOrEmail = StringUtils.trimToNull(request.getParameter("usernameOrEmail"));
ReCaptcha captcha;
if (settingsService.getHttpsPort() != 0) {
captcha = ReCaptchaFactory.newSecureReCaptcha(
"6LcZ3OMSAAAAANkKMdFdaNopWu9iS03V-nLOuoiH",
"6LcZ3OMSAAAAAPaFg89mEzs-Ft0fIu7wxfKtkwmQ", false);
} else {
captcha = ReCaptchaFactory.newReCaptcha(
"6LcZ3OMSAAAAANkKMdFdaNopWu9iS03V-nLOuoiH",
"6LcZ3OMSAAAAAPaFg89mEzs-Ft0fIu7wxfKtkwmQ", false);
}
boolean showCaptcha = true;
if (usernameOrEmail != null) {
map.put("usernameOrEmail", usernameOrEmail);
User user = getUserByUsernameOrEmail(usernameOrEmail);
String challenge = request.getParameter("recaptcha_challenge_field");
String uresponse = request.getParameter("recaptcha_response_field");
ReCaptchaResponse captchaResponse = captcha.checkAnswer(request.getRemoteAddr(), challenge, uresponse);
if (!captchaResponse.isValid()) {
map.put("error", "recover.error.invalidcaptcha");
} else if (user == null) {
map.put("error", "recover.error.usernotfound");
} else if (user.getEmail() == null) {
map.put("error", "recover.error.noemail");
} else {
String password = RandomStringUtils.randomAlphanumeric(8);
if (emailPassword(password, user.getUsername(), user.getEmail())) {
map.put("sentTo", user.getEmail());
user.setLdapAuthenticated(false);
user.setPassword(password);
securityService.updateUser(user);
showCaptcha = false;
} else {
map.put("error", "recover.error.sendfailed");
}
}
}
if (showCaptcha) {
map.put("captcha", captcha.createRecaptchaHtml(null, null));
}
return new ModelAndView("recover", "model", map);
}