liferay ui:liferay 6.2中的验证码自定义/本地化

liferay ui:liferay 6.2中的验证码自定义/本地化,liferay,liferay-6,liferay-aui,Liferay,Liferay 6,Liferay Aui,迁移到Liferay 6.2后,自定义停止工作: 原始输入不再隐藏 出现刷新链接(我们需要隐藏它,或者转换标签并删除有错误的工具提示-它在悬停时闪烁) 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 fo

迁移到Liferay 6.2后,自定义停止工作:

  • 原始输入不再隐藏
  • 出现刷新链接(我们需要隐藏它,或者转换标签并删除有错误的工具提示-它在悬停时闪烁)
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"  />
xmlns:form=”http://www.springframework.org/tags/form" 
xmlns:liferay ui=”http://liferay.com/tld/ui"
Opiste文本z obrazku
定制验证码组件的正确方法是什么

我尝试替换我们的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 taglib代码。。。我不确定您是否可以钩住标记库。

您可以通过钩子自定义UI标记库:验证码。这里有一个例子。在本例中,我通过属性设置了reCaptcha的主题。

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.");
            }
import com.liferay.portal.kernel.captcha.CaptchaException;
导入com.liferay.portal.kernel.captcha.CaptchaUtil;
@资源地图
public void服务器资源(ResourceRequest ResourceRequest,
ResourceResponse(ResourceResponse)引发IOException{
CaptchaUtil.serveImage(resourceRequest,resourceResponse);
}
私有字符串getCaptchaValueFromSession(PortletSession会话){
枚举atNames=session.getAttributeNames();
while(atNames.hasMoreElements()){
字符串名称=atNames.nextElement();
如果(名称包含(“验证码文本”)){
返回(字符串)session.getAttribute(名称);
}
}
返回null;
}
验证验证码文本
PortletSession会话=actionRequest.getPortletSession();
字符串enteredCaptChatText=ParamUtil.getString(actionRequest,“CaptChatText”);
字符串captchaText=getCaptchaValueFromSession(会话);
if(Validator.isNull(captchaText)| |!StringUtils.equals(captchaText,enteredCaptchaText)){
抛出新的验证码异常(“无效验证码文本。请重新输入”);
}

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