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


Java ReCaptchaFactory类代码示例

本文整理汇总了Java中net.tanesha.recaptcha.ReCaptchaFactory的典型用法代码示例。如果您正苦于以下问题:Java ReCaptchaFactory类的具体用法?Java ReCaptchaFactory怎么用?Java ReCaptchaFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReCaptchaFactory类属于net.tanesha.recaptcha包,在下文中一共展示了ReCaptchaFactory类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: register

import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@Override
public String register(ModelMap model, HttpSession session) {


	model.addAttribute("openSourceLinks", 
			new OpenSourceLink[]{
			new OpenSourceLink("View this page's jsp code.", "https://github.com/KevinWorkman/StaticVoidGames/blob/master/StaticVoidGames/src/main/webapp/WEB-INF/jsp/register.jsp"),
			new OpenSourceLink("View this page's server code.", "https://github.com/KevinWorkman/StaticVoidGames/blob/master/StaticVoidGames/src/main/java/com/StaticVoidGames/spring/controller/StaticVoidGamesController.java")
	}
			);


	String recaptchaPublicKey = env.getProperty("recaptcha.publicKey");
	String recaptchaPrivateKey = env.getProperty("recaptcha.privateKey");

	ReCaptcha c = ReCaptchaFactory.newReCaptcha(recaptchaPublicKey, recaptchaPrivateKey, false);
	model.addAttribute("recaptchaHtml", c.createRecaptchaHtml(null, null));

	return "register";
}
 
开发者ID:KevinWorkman,项目名称:StaticVoidGames,代码行数:21,代码来源:StaticVoidGamesController.java

示例3: isCaptchaValid

import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
private boolean isCaptchaValid(SignUpCredentials creds, SignUpValidationResult result_out, String remoteAddress)
{
	String captchaChallenge = creds.getCaptchaChallenge();
	String captchaResponse = creds.get(E_SignUpCredentialType.CAPTCHA_RESPONSE);
	
	ReCaptcha captcha = ReCaptchaFactory.newReCaptcha(m_publicRecaptchaKey, m_privateRecaptchaKey, false);
       ReCaptchaResponse recaptchaResponse = captcha.checkAnswer(remoteAddress, captchaChallenge, captchaResponse);

       if ( !recaptchaResponse.isValid())
       {
       	result_out.setNoErrors(); // just make sure all errors are filled in for json writing...kinda hacky.
       	result_out.setError(E_SignUpCredentialType.CAPTCHA_RESPONSE, E_SignUpValidationError.CAPTCHA_INCORRECT);
       	
       	return false;
       }
       
       return true;
}
 
开发者ID:dougkoellmer,项目名称:swarm,代码行数:19,代码来源:signUp.java

示例4: 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

示例5: doGet

import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
	String cacheKey = "page-contact";
	String output = null;
	Cache cache = CacheSingleton.getInstance().getCache();
	if (cache.containsKey(cacheKey)) {
		output = (String) cache.get(cacheKey);
	} else {
		ConfigManager configManager = ConfigManager.getInstance();

		ReCaptcha captcha = ReCaptchaFactory
				.newReCaptcha(
						configManager
								.getValue(ConfigManager.RECAPTCHA_PUBLIC_KEY),
						configManager
								.getValue(ConfigManager.RECAPTCHA_PRIVATE_KEY),
						false);
		String captchaScript = captcha.createRecaptchaHtml(
				req.getParameter("error"), null);

		VelocityContext context = prepareContext(req);
		context.put(
				"pageTitle",
				"Contact form and information"
						+ configManager
								.getValue(ConfigManager.WEBSITE_TITLE_SUFFIX));
		context.put("htmlCaptcha", captchaScript);
		output = generateTemplate("contact.vm", context);
		cache.put(cacheKey, output);
	}
	writeResponse(output, resp);
}
 
开发者ID:santiagolizardo,项目名称:jerba,代码行数:33,代码来源:ContactServlet.java

示例6: 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

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

示例8: 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

示例9: 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

示例10: buildCreateContext

import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
/**
 * 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";

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:56,代码来源:UsersAction.java

示例11: doPost

import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {

	Properties props = new Properties();
	Session session = Session.getDefaultInstance(props, null);

	String fromName = req.getParameter("fromName");
	String fromEmail = req.getParameter("fromEmail");
	String msgBody = req.getParameter("message");

	String challengeParam = req.getParameter("recaptcha_challenge_field");
	String responseParam = req.getParameter("recaptcha_response_field");

	if (null == fromName || null == fromEmail || null == msgBody
			|| null == challengeParam || null == responseParam) {
		LOGGER.warning("Invalid/missing params");
		sendErrorResponse(resp, HttpServletResponse.SC_NOT_FOUND);
		return;
	}

	String remoteAddr = req.getRemoteAddr();

	ConfigManager configManager = ConfigManager.getInstance();

	ReCaptcha captcha = ReCaptchaFactory.newReCaptcha(
			configManager.getValue(ConfigManager.RECAPTCHA_PUBLIC_KEY),
			configManager.getValue(ConfigManager.RECAPTCHA_PRIVATE_KEY),
			false);
	ReCaptchaResponse response = captcha.checkAnswer(remoteAddr,
			challengeParam, responseParam);

	if (!response.isValid()) {
		resp.sendRedirect("/contact?error=" + response.getErrorMessage());
	} else {
		InternetAddress address = new InternetAddress(
				configManager.getValue(ConfigManager.ADMINISTRATOR_EMAIL),
				configManager.getValue(ConfigManager.ADMINISTRATOR_NAME));

		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(address);
			msg.addRecipient(Message.RecipientType.TO, address);
			msg.setSubject("Contact form");
			String header = String.format("From: %s (%s)%n%n", fromName,
					fromEmail);
			msg.setText(header + msgBody);
			Transport.send(msg);
		} catch (Exception e) {
			LOGGER.warning(e.getMessage());
			sendErrorResponse(resp);
			return;
		}
	}

	resp.sendRedirect("/");
}
 
开发者ID:santiagolizardo,项目名称:jerba,代码行数:58,代码来源:ContactServlet.java

示例12: 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

示例13: makeReCaptcha

import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
public ReCaptcha makeReCaptcha(){
    return ReCaptchaFactory.newReCaptcha(publicKey, privateKey, false);
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:4,代码来源:RecaptchaAction.java

示例14: getText

import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@Override protected String getText(final Arguments arguments, final Element element, final String attributeName) {
	final String recaptchaPublicKey = "6LceYuESAAAAAG-s2C1bzURTlpt6niMTMmnHTKuT";
	final String recaptchaPrivateKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
	final ReCaptcha captcha = ReCaptchaFactory.newReCaptcha(recaptchaPublicKey, recaptchaPrivateKey, false);
	return captcha.createRecaptchaHtml(null, null);
}
 
开发者ID:llop,项目名称:porra-joc-eda,代码行数:7,代码来源:ReCaptchaAttrProcessor.java


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