Foros de discusión

Captcha Not working in Liferay DXP

thumbnail
Murtaza Ghadiali, modificado hace 7 años.

Captcha Not working in Liferay DXP

New Member Mensajes: 11 Fecha de incorporación: 3/03/14 Mensajes recientes
Hi,

I had implement liferay captcha in DXP but it is not working.

Following is the code that I had used.

On Jsp :-

<portlet:resourceURL id="/captcha" var="captchaURL">
</portlet:resourceURL>
<liferay-ui:captcha url="<%=captchaURL%>" />

Below is the class


@Component(property = { "javax.portlet.name=" + ContactUsRegistrationConstant.CONTACTUS_REGISTRATION_PORTLET_ID,
"mvc.command.name=/captcha" }, service = MVCResourceCommand.class)
public class CaptchaMVCResourceCommand implements MVCResourceCommand {

/** The Constant _log. */
private static final Log _log = LogFactoryUtil.getLog(CaptchaMVCResourceCommand.class);

/*
* (non-Javadoc)
*
* @see com.liferay.portal.kernel.portlet.bridges.mvc.MVCResourceCommand#
* serveResource(javax.portlet.ResourceRequest,
* javax.portlet.ResourceResponse)
*/
@Override
public boolean serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws PortletException {
try {
CaptchaUtil.serveImage(resourceRequest, resourceResponse);
return false;
} catch (Exception e) {
_log.error(e, e);
return true;
}
}

}
John Lulich, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 10 Fecha de incorporación: 19/04/16 Mensajes recientes
I'm about to work on the same type of thing. Have you figured out the problem yet?

Cheers,
John
Arti Gupta, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 5 Fecha de incorporación: 29/04/13 Mensajes recientes
Hi Murtaza,John

I also facing the same problem . need to implement captcha for signin portlet but it is not working.
Have your issue resolved ?

Any help really appreciated.

Thanks,
Arti Gupta
thumbnail
pablo iglesias, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 9 Fecha de incorporación: 16/12/13 Mensajes recientes
Hi,
Actually I do not render the captcha with the tag liferay-ui: captcha, I did it in the following way:

jsp:


<portlet:actionurl name="/contact/contact" var="contactActionURL" />
<portlet:resourceurl id="/contact/captcha" var="captchaURL" />
<liferay-ui:error exception="<%= CaptchaException.class %>" message="text-verification-failed" />

<form action="${contactActionURL}" method="post">
                                <img alt="captcha" class="captcha" id="captchaImg" src="${captchaURL}">
				<liferay-ui:icon cssClass="refresh" iconCssClass="icon-refresh" id="refreshCaptcha" label="<%= false %>" localizeMessage="<%= true %>" message="refresh-captcha" url="javascript:;" />

				<input name="<portlet:namespace />captchaText" id="<portlet:namespace />captchaText" size="10" type="text" value="" required>
</form>
<aui:script>

	$('#<portlet:namespace />refreshCaptcha').on("click",
			function(ev){
				$("#captchaImg").attr('src', '${captchaURL}&amp;force=' + encodeURIComponent(Math.floor(Math.random() * Math.pow(2, 53))));
			});
</aui:script>


Resource comand class:

@Component(
	 immediate = true,
	 property = {
		        "javax.portlet.name=" + FormulariosConstantes.PORTLET_FORMULARIOS_CONTACTANOS,
		        "mvc.command.name=/contact/captcha"
		    },
		    service = MVCResourceCommand.class
)

public class CaptchaMVCResourceCommand extends BaseMVCResourceCommand{

	private final Log _log = LogFactoryUtil.getLog(
			CaptchaMVCResourceCommand.class); 
	
	@Override
	protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
			throws Exception {
		
		ParamUtil.print(resourceRequest);
		try {
			
			CaptchaUtil.serveImage(
					resourceRequest, resourceResponse);
			
		} catch (Exception e) {
			_log.error(e.getMessage());
		}
			
	}	
}


Action Class:


@Component(
		immediate = true,
		property ={
				"javax.portlet.name=" + FormulariosConstantes.PORTLET_FORMULARIOS_CONTACTANOS,
				"mvc.command.name=/contact/contact"
		},
		service = MVCActionCommand.class
)
@Override
	protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
		
		ParamUtil.print(actionRequest);
		try {
			CaptchaUtil.check(actionRequest);
            } catch (CaptchaException e) {
				  SessionErrors.add(actionRequest, CaptchaException.class);
		}



I hope you have solved the problem
Arti Gupta, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 5 Fecha de incorporación: 29/04/13 Mensajes recientes
Hi pablo iglesias,

Thanks for the quick reply. Actually i stucked to implement captcha in SignIn Portlet.
For implementing Captcha In SignIn Portlet
Need to customise
1. login.jsp
2.Add MVCResourceCommand for LogIn portlet
3 Override LoginMVCActionCommandAction

I created the fragment and add your JSP code
it's working well .

But the problem for calling the serveImage method need to implement MVCResource command
So ,i created another Component for add CustomMvcResource command .
and when I tried to deploy it showing me error

Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/kernel/portlet/bridges/mvc/BaseMVCResourceCommand

For detail PFA log file.

Here i am attaching my source code
Any Help really appreciated .
Arti Gupta, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 5 Fecha de incorporación: 29/04/13 Mensajes recientes
Any Help???
Do i need to put any changes in properties file??
thumbnail
pablo iglesias, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 9 Fecha de incorporación: 16/12/13 Mensajes recientes
Hello,

you do not need to put anything in the properties file.
Arti Gupta, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 5 Fecha de incorporación: 29/04/13 Mensajes recientes
Hi pablo iglesias,

Thanks for the quick reply. Actually i stucked to implement captcha in SignIn Portlet.
For implementing Captcha In SignIn Portlet
Need to customise
1. login.jsp
2.Add MVCResourceCommand for LogIn portlet
3 Override LoginMVCActionCommandAction

I created the fragment and add your JSP code
it's working well .

But the problem while calling the serveImage method need to implement MVCResource command
So ,i created another Component for add CustomMvcResource command .
and when I tried to deploy it showing me error

Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/kernel/portlet/bridges/mvc/BaseMVCResourceCommand

For detail PFA log file.

Here i am attaching my source code
Any Help really appreciated .
thumbnail
Jignesh Vachhani, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

Liferay Master Mensajes: 803 Fecha de incorporación: 10/03/08 Mensajes recientes
Remove
Import-Package: com.liferay.login.web.constants
-sources: true
from Login-web-hook .bnd file.
This will resolve your issue of class loading and you will be able to see Liferay captcha
thumbnail
Joye Luo, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

Regular Member Mensajes: 144 Fecha de incorporación: 3/05/16 Mensajes recientes
Hey Murtaza,

I have met the same issue as u.
Did you find the solution?
thumbnail
Joye Luo, modificado hace 6 años.

RE: Captcha Not working in Liferay DXP

Regular Member Mensajes: 144 Fecha de incorporación: 3/05/16 Mensajes recientes
I solved my problem by change
<liferay-ui:captcha url="<%= captchaURL %>
to <liferay-captcha:captcha url="<%= captchaURL %>" />

See ticket https://issues.liferay.com/browse/LPS-69383
Pradnya Parvatikar, modificado hace 4 años.

RE: Captcha Not working in Liferay DXP

New Member Mensajes: 10 Fecha de incorporación: 3/11/17 Mensajes recientes
Please try with the following in jsp:
<%@taglib uri="http://liferay.com/tld/captcha" prefix="liferay-captcha" %>
<%@page import="com.liferay.portal.kernel.captcha.Captcha"%>

<portlet:resourceURL var="captchaURL"/>
​​​​​​​
<liferay-captcha:captcha url="${captchaURL}" />