迁移到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来做到这一点,但我会对正确的方法感兴趣。
由于
答案 0 :(得分:0)
我认为最好的方法应该是在ext环境中工作,修改你的UI taglib代码......我不确定你是否可以挂钩taglib。
答案 1 :(得分:0)
您可以通过hook自定义UI taglib:captcha。这是一个例子enter link description here。在这个例子中,我通过属性设置了reCaptcha的主题。
答案 2 :(得分:0)
用于创建简单验证码的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.");
}