Fórum

Add Captcha In Sign in Portlet

thumbnail
Puneet Upadhyay, modificado 12 Anos atrás.

Add Captcha In Sign in Portlet

Regular Member Postagens: 234 Data de Entrada: 22/10/11 Postagens Recentes
Please tell me how to add captcha in sign in portlet.
thumbnail
Mani kandan, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Expert Postagens: 492 Data de Entrada: 15/09/10 Postagens Recentes
You can get it here blog

And you can get full coding here link
thumbnail
Puneet Upadhyay, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 234 Data de Entrada: 22/10/11 Postagens Recentes
Thanks Mani but i am unable to do this is sign in portlet.
will you please elaborate this???
thumbnail
Puneet Upadhyay, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 234 Data de Entrada: 22/10/11 Postagens Recentes
I am trying to attach captcha in sign in portlet but i am unable to do it.
Can anybody tell me the full procedure i mean steps. which jsp, and class i need to extend???
thumbnail
srikanth a, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 144 Data de Entrada: 21/02/11 Postagens Recentes
Hi Puneeth,
Please follow these below steps to create and validate the captcha. Hope it will help you.

Generate Captcha

In JSPPortlet class we need to add method serverResource - something like this:

public class CaptchaSamplePortlet extends JSPPortlet {
/** Serve Resource used for getting captcha
*
*/
@Override
public void serveResource(ResourceRequest resourceRequest,
ResourceResponse resourceResponse) throws IOException, PortletException {
try {
com.liferay.portal.kernel.captcha.CaptchaUtil.serveImage(resourceRequest, resourceResponse);
} catch (Exception e) {
log.error(e);
}
}
}
This method doing everything - generated captcha and returned it's content (with all required http-readers into response), as well as placed required data into session

Display Captcha

Now, to place captcha into jsp you need to place:

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

That will place captcha control and point it to our portlet resourceURL to generate image

Now, you will have captcha and field to enter captcha text on your form generated by these tags.

Validate Captcha

To check captcha add followed function in your action-handler in portlet-class:


private void checkCaptcha(PortletRequest request) throws Exception {
String enteredCaptchaText = ParamUtil.getString(request, "captchaText");

PortletSession session = request.getPortletSession();
String captchaText = getCaptchaValueFromSession(session);
if (Validator.isNull(captchaText)) {
throw new Exception("Internal Error! Captcha text not found in session");
}
if (!StringUtils.equals(captchaText, enteredCaptchaText)) {
throw new Exception("Invalid captcha text. Please reenter.");
}
}

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;
}
What is all - now, you can do everything - display captcha, enter value - and check it
thumbnail
Puneet Upadhyay, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 234 Data de Entrada: 22/10/11 Postagens Recentes
Hi Srikanth,

Thanks for nice explanation. But i am very new to liferay please specify all the steps
i.e. which jsp and which class i need to extend??
Thanks.
thumbnail
srikanth a, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 144 Data de Entrada: 21/02/11 Postagens Recentes
Hi,
In your portlet class overide the serveresource method add the above line inside serveresource.
Add 'Displaycapcha' code in the jsp where you want to see the captcha.
To validate the captcha add above lines of in the proceesaction of your portlet class.



regards
Sri.
thumbnail
Puneet Upadhyay, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 234 Data de Entrada: 22/10/11 Postagens Recentes
Ok Sri. I try this
thumbnail
chirag dashalaniya, modificado 11 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 129 Data de Entrada: 21/12/11 Postagens Recentes
Your blog link is very helpful to me and i got captcha image in my custom portlet ,but i want one Refresh Buttton beside catpch image and when user click only captch image reload though ajax

Give Me some Hint Regarding Ajax call in liferay 6.1
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
@chirag
Can you please share some hint or link ti create Captcha
thumbnail
chirag @ India, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 129 Data de Entrada: 21/12/11 Postagens Recentes
hi azaruddin ,

thanks for your reply .Actually i implemented captcha in custom portlet. now i want to refresh captcha field only not whole form .



I created captcha using below link..

http://www.emforge.net/web/akakunin/home/-/blogs/implement-captcha-in-liferay-portlet.

Thanks
Chirag
thumbnail
Manish Yadav, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Expert Postagens: 493 Data de Entrada: 26/05/12 Postagens Recentes
Hi Chirag ,

You can use below code for refresh captcha using jquery.

SCRIPT

<script>
jQuery("#refreshCaptchaActivity").click(function() {
	 jQuery(".captcha").attr("src", jQuery(".captcha").attr("src")+"&force=" + new Date().getMilliseconds());
	 return false;
}); 
</script>



HTML

<div>
				<liferay-ui:captcha url="<%=captchaURLForActivity%>" />
			<div style="float:left;padding:23px 0 0 5px;cursor: pointer;">
		<img id="refreshCaptchaActivity" src="<%= request.getContextPath()%>/images/refresh.png">
			</div>
</div>


Please let me know if you require more inputs
Regards
Manish Banwari lal Yadav
thumbnail
chirag @ India, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 129 Data de Entrada: 21/12/11 Postagens Recentes
hi manish ,

Thanks for your reply...its working for the first time when portlet render from add menu from dock ,but when i refresh page then it is not working..

First i have written alert for checking that function is call or not ,so first time it dialog display ,but not display after page refresh..

jQuery("#refreshCaptchaActivity").click(function()
		{
	alert("hii");
	jQuery(".captcha").attr("src", jQuery(".captcha").attr("src")+"&amp;force=" + new Date().getMilliseconds());
	return false;
		});


in liferay-portlet.xml setting..

<header-portlet-javascript>http://code.jquery.com/jquery-1.4.2.min.js</header-portlet-javascript>

all try with

<header-portlet-javascript>/js/jquery-1.7.1.min.js</header-portlet-javascript>

I have checked by inspect element there is loaded js..& also not getting any error like uncaught JQuery...

Thanks

HELP ME
John Carter, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Junior Member Postagens: 53 Data de Entrada: 18/10/12 Postagens Recentes
Hi chirag,
Simply I have written the below line in jsp and used the above code , just for checking and it working fine for me.

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
thumbnail
Manish Yadav, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Expert Postagens: 493 Data de Entrada: 26/05/12 Postagens Recentes
Hi Chriag,
if you not able to view alert box after page refresh it means javascript itself not working after page refresh. Because alert should display after clicking refreshCaptchaActivity id .

might be chance of conflict of refreshCaptchaActivity id

use below code

<div>
<liferay-ui:captcha url="<%=captchaURLForActivity%>"/>
<div style="float:left;padding:23px 0 0 5px;cursor: pointer;">
<img class="refreshCaptchaActivity" src="<%= request.getContextPath()%>/images/refresh.png">
</div>
</div>

JAVASCRIPT


jQuery(".refreshCaptchaActivity").click(function()
{
alert("hii");
jQuery(".captcha").attr("src", jQuery(".captcha").attr("src")+"&force=" + new Date().getMilliseconds());
return false;
});


Regards
Manish Banwari Lal Yadav
thumbnail
chirag @ India, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 129 Data de Entrada: 21/12/11 Postagens Recentes
hi manish,

thanks its working cheersemoticon
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: Add Captcha In Sign in Portlet

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
Hi try this recapcha..working on it
thumbnail
Szymon Gołębiewski, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 246 Data de Entrada: 08/06/09 Postagens Recentes
Puneet Upadhyay:
Please tell me how to add captcha in sign in portlet.

What Liferay version are you using? I think captcha and reCaptcha are in Liferay by default
thumbnail
Puneet Upadhyay, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 234 Data de Entrada: 22/10/11 Postagens Recentes
i am using 6.1 version.
thumbnail
Szymon Gołębiewski, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

Regular Member Postagens: 246 Data de Entrada: 08/06/09 Postagens Recentes
Puneet Upadhyay:
i am using 6.1 version.



You can easily add reCaptcha to your system. In portal-ext.properties add this
captcha.engine.impl=com.liferay.portal.captcha.recaptcha.ReCaptchaImpl
and fill those two properties with keys you will get from reCaptcha website
captcha.engine.recaptcha.key.private=
captcha.engine.recaptcha.key.public=

And that is all
Vlad Kuzmyk, modificado 12 Anos atrás.

RE: Add Captcha In Sign in Portlet

New Member Postagens: 10 Data de Entrada: 18/01/12 Postagens Recentes
Yes, but for login screen you need to add a captcha control to the jsp page like it described here:
http://lanbuithe.blogspot.com/2011/08/enabling-captcha-in-login-portlet.html

Then you have to extend the ProcessAction to include captcha validation, otherwise it won't check what you entered.
Mustafa Yüceel, modificado 11 Anos atrás.

RE: Add Captcha In Sign in Portlet

New Member Mensagem: 1 Data de Entrada: 02/10/12 Postagens Recentes
Puneet Upadhyay:
Please tell me how to add captcha in sign in portlet.


It is a bit old question but if someone needs, here is the explanations: http://mustafayuceel.com/my/how-to-activate-catpcha-recaptcha-in-liferay-6-login-page/
thumbnail
Szymon Gołębiewski, modificado 11 Anos atrás.

Automatyczna odpowiedź: [Liferay Forums][3. Development] RE: Add Captcha In

Regular Member Postagens: 246 Data de Entrada: 08/06/09 Postagens Recentes
W dniach 9 - 10 kwietnia przebywam poza firmą z ograniczonym dostępem do poczty elektronicznej. W sprawach pilnych proszę o kontakt z Gawłem Bogutą (gawel.boguta@eo.pl<mailto:gawel.boguta@eo.pl>).

Pozdrawiam,
Szymon Gołębiewski