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.

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...