Google reCaptcha не возвращает никакого ответа - PullRequest
0 голосов
/ 27 марта 2019

Я добавляю google reCaptcha на страницу входа. Отправка формы входа в систему реализована с использованием j_security_check в JavaServer Faces Forms и JSF 1.2. Веб-приложение, запущенное на WyldFly 10. Панель капчи появляется на странице, как и ожидалось. Но он не возвращает никакого ответа на метод doLoginAction ().

Форма в моем логине.xhtml:

<form method="POST" action="j_security_check" name="loginForm" autocomplete="off" id="loginForm" onsubmit="return checkBeforeSubmit();">
            <div id="boxtop"></div>
            <div id="boxmid">
                <div class="section">
                    <span><h:outputText id="usernameLabel" value="#{msg['page.login.username']}"/></span>
                    <input type="text" id="j_username" name="j_username" maxlength="60" autocomplete="off" 
                           onfocus="this.value = '';" onblur="if (this.value == '') {
                                       this.value = '#{msg['page.login.label']}';
                                   }" 
                           value="#{msg['page.login.label']}" />
                </div>  
                <div class="section">
                    <span><h:outputText id="passwordLabel" value="#{msg['page.login.password']}"/></span>
                    <input type="text" style="display:none;" />
                    <input type="password" id="j_password" name="j_password" maxlength="20" autocomplete="off"
                           onfocus="this.value = '';" onblur="if (this.value == '') {
                                       this.value = '#{msg['page.login.password.label']}';}"
                           value="#{msg['page.login.password.label']}" />
                </div>               
                <div class="g-recaptcha" data-sitekey="my-site-key"></div>                          
            <div class="text" style="float: right;">
                <input type="submit" value="Zaloguj" name="login" class="submit"  onclick="#{LoginBean.doLoginAction()}"/>
            </div>
        </form>

Мой логинLayout.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>
        <link rel="shortcut icon" href="${request.contextPath}/img/icons/favicon.ico" id="favicon" type="image/x-icon"/>
        <title>jLeo</title>
        <meta name="description" content="" />
        <meta name="keywords" content="" />

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="refresh"
              content="${session.maxInactiveInterval};url=${request.contextPath}/sessionTimeout.xhtml"/>
        <a4j:loadStyle src="resource:///pl/com/adh/jleo/skin/#{LoginBean.skin}/css/default.css"/>
        <link href="${request.contextPath}/css/login/style.css" rel="stylesheet"  type="text/css" title="style" media="screen" />
        <script src="https://www.google.com/recaptcha/api.js"></script>
    </head>
    <body>       
    </body>
    <script src="${request.contextPath}/js/allLogin.js" type="text/javascript"></script>
</html>

Мой метод doLoginAction () в LoginBean:

 public String doLoginAction() {
         try {
        //here must be some response instead of null
        String gRecaptchaResponse = FacesContext.getCurrentInstance().
        getExternalContext().getRequestParameterMap().get("g-recaptcha-response");
        boolean verify = VerifyRecaptcha.verify(gRecaptchaResponse);
        if(verify){
             return "Success";
        }else{
             FacesContext context = FacesContext.getCurrentInstance();
             context.addMessage( null, new FacesMessage( "Select Captcha") );
             return null;
          }
         } catch (Exception e) {
             System.out.println(e);
         }
        return null;
     }    

Во время отладки я получаю нулевое значение для gRecaptchaResponse вместо ответа.

...