当前位置: 首页>>代码示例>>Java>>正文


Java ReCaptchaFactory.newSecureReCaptcha方法代码示例

本文整理汇总了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 "";
}
 
开发者ID:apache,项目名称:rave,代码行数:20,代码来源:ReCaptchaService.java

示例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);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:44,代码来源:RecoverController.java

示例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;

}
 
开发者ID:apache,项目名称:rave,代码行数:32,代码来源:ReCaptchaService.java

示例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 "";
}
 
开发者ID:nitram509,项目名称:tweet-gateway-server,代码行数:8,代码来源:ReCaptchaService.java

示例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);
}
 
开发者ID:apache,项目名称:usergrid,代码行数:9,代码来源:AbstractContextResource.java

示例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);
    }
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:43,代码来源:MultiController.java

示例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);
    }
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:54,代码来源:MultiController.java


注:本文中的net.tanesha.recaptcha.ReCaptchaFactory.newSecureReCaptcha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。