【问题标题】:liferay-ui:captcha customization/localization in Liferay 6.2liferay-ui:Liferay 6.2 中的验证码定制/本地化
【发布时间】:2018-09-06 03:09:36
【问题描述】:

迁移到 Liferay 6.2 后,<liferay-ui:captcha> 自定义停止工作:

  • 原始输入不再隐藏
  • 刷新链接出现(我们需要隐藏它,或者翻译标签并删除错误的工具提示 - 它在悬停时闪烁)

LFR 6.1 代码:

xmlns:form="http://www.springframework.org/tags/form" 
xmlns:liferay-ui="http://liferay.com/tld/ui"

<liferay-ui:captcha url="${captchaURL}"/>
<label for="captchaText" >
    Opiste text z obrazku
</label>
<form:input id="captchaText" path="captcha"  />

自定义验证码组件的正确方法是什么?

我尝试替换我们的 id 以匹配 Liferay 生成的字段的 id,但它不起作用。

Liferay 生成的代码:

<div class="taglib-captcha" id="yui_patched_v3_11_0_1_1425121596007_13262">
    <img alt="Text to Identify" class="captcha"
         id="_pspmlmuserportlet_WAR_pspmlmuserportlet_captcha"
         src="..."/>
    <span class="refresh" onmouseover="Liferay.Portal.ToolTip.show(this, 'Refresh CAPTCHA')" 
          data-title="" id="yui_patched_v3_11_0_1_1425121596007_13261"> 

        <a href="javascript:;" class=" taglib-icon" id="_pspmlmuserportlet_WAR_pspmlmuserportlet_refreshCaptcha">
            <img id="refreshCaptcha" src=".../refresh.png" alt="Refresh CAPTCHA" title="Refresh CAPTCHA"/> 
            <span class="taglib-text hide-accessible">Refresh CAPTCHA</span> 
        </a> 
    </span>

    <div class="form-group" id="yui_patched_v3_11_0_1_1425121596007_14890">
        <label class="control-label" for="_pspmlmuserportlet_WAR_pspmlmuserportlet_captchaText"> 
            Text Verification <span class="label-required">(Required)</span>
        </label>
        <input class="field  form-control" id="_pspmlmuserportlet_WAR_pspmlmuserportlet_captchaText"
               name="_pspmlmuserportlet_WAR_pspmlmuserportlet_captchaText" type="text" value="" size="10"/>
    </div>
</div>

我可能可以通过 jQuery 来完成,但我会对正确的方式感兴趣。

谢谢

【问题讨论】:

    标签: liferay liferay-6 liferay-aui


    【解决方案1】:

    我认为最好的方法应该是在 ext 环境中工作,用于修改你的 UI taglib 代码......我不确定你是否可以挂钩 taglib。

    【讨论】:

    • 那么 Liferay 6.2 不支持任何自定义,即使 Liferay 6.1 支持?
    • LR 正在推动增加自定义功能...所以一般来说,您可以在 6.2 中自定义至少与 6.1 中相同的内容(对不起,如果我的回答可能有不同的解释)。顺便说一句,6.2 中的代码(对于相同的用户行为)可能与 6.1 中的不同......因此您应该从 6.2 源代码开始自定义您的行为并尝试应用您需要的内容。
    【解决方案2】:

    您可以通过钩子自定义 UI taglib: captcha。这是一个例子enter link description here。在这个例子中,我通过属性设置了 reCaptcha 的主题。

    【讨论】:

      【解决方案3】:

      Liferay 6.2 创建简单验证码的代码

      <%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui"%>
      <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
      <%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
      

      在显示验证码图像之前将调用此 URL

      <portlet:resourceURL var="captchaURL"/>
      

      这是显示图像的 Html 代码

      <aui:column columnWidth="10" first="true">
      <div class="input-piwest-captcha">
      <liferay-ui:captcha url="<%=captchaURL%>" />
      </div>
      <div class="input-piwest-captchaError">
      <liferay-ui:error key="errorMessage" message="Code does not match. Please try again."/>
      </div>
      </aui:column>
      

      Java 代码

      import com.liferay.portal.kernel.captcha.CaptchaException;
      import com.liferay.portal.kernel.captcha.CaptchaUtil;
      
        @ResourceMapping
      public void serveResource(ResourceRequest resourceRequest,
              ResourceResponse resourceResponse) throws IOException  {
              CaptchaUtil.serveImage(resourceRequest, resourceResponse);
      }
      
      
      
       private String getCaptchaValueFromSession(PortletSession session) {
              Enumeration<String> atNames = session.getAttributeNames();
              while (atNames.hasMoreElements()) {
                  String name = atNames.nextElement();
                  if (name.contains("CAPTCHA_TEXT")) {
                      return (String) session.getAttribute(name);
                  }
              }
              return null;
          }
      
      
      
          Validate the CAPTCHA TEXT
      
                PortletSession session = actionRequest.getPortletSession();
                String enteredCaptchaText = ParamUtil.getString(actionRequest, "captchaText");
                  String captchaText = getCaptchaValueFromSession(session);
      
                  if (Validator.isNull(captchaText) || !StringUtils.equals(captchaText, enteredCaptchaText)) {
                      throw new CaptchaException("Invalid captcha text. Please reenter.");
                  }
      

      【讨论】:

        猜你喜欢
        • 2015-02-25
        • 2014-01-14
        • 2016-05-11
        • 2010-10-31
        • 2015-04-11
        • 1970-01-01
        • 1970-01-01
        • 2021-07-28
        • 2023-03-26
        相关资源
        最近更新 更多