13 June, 2017

Captcha & reCaptcha with Liferay 7

If you are planning to integrate captcha in you liferay custom portlet then use below stuff


view.jsp:
<%@taglib uri="http://liferay.com/tld/captcha" prefix="liferay-captcha" %>
<portlet:resourceURL id="/login/captcha" var="captchaURL"/>
<liferay-captcha:captcha url="<%=captchaURL%>" />


Write CaptchaMVCResourceCommand.java :

@Component(
    property = {
        "javax.portlet.name=test_portlet",
        "mvc.command.name=/login/captcha"
    },
    service = MVCResourceCommand.class
)
public class CaptchaMVCResourceCommand extends BaseMVCResourceCommand {

    @Override
    public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse) {

        try {
            CaptchaUtil.serveImage(resourceRequest, resourceResponse);
            return false;
        }
        catch (Exception e) {
            _log.error(e, e);

            return true;
        }
    }

And you are done...

Make sure you use <liferay-captcha:captcha url="<%=captchaURL%>" />  instead of <liferay-ui:captcha url="<%=captchaURL%>" /> as its not support in custom module somehow.

Rate Me:

0 Discussion:

Post a Comment

Your Comments on this post

Create Servlet Project as Module

You would have seen that many times we are writing out own servlet in Liferay portal to achieve some specific use case. In DXP, You can st...