liferay ui:liferay 6.2中的captcha定制/本地化



迁移到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"  />

定制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来完成,但我对正确的方法感兴趣

感谢

我认为最好的方法应该是在ext环境中工作,用于修改UI标签库代码。。。我不确定你能不能钩住一个标签。

您可以通过钩子自定义UI标签库:captcha。这里有一个输入链接描述的例子。在这个例子中,我通过属性设置了reCaptcha的主题。

Liferay 6.2代码,用于创建一个简单的captcha

<%@ 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将在显示CAPTCHA图像之前调用

<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.");
            }

最新更新