Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Add Captcha In Sign in Portlet Puneet Upadhyay November 10, 2011 8:38 PM
RE: Add Captcha In Sign in Portlet Manikandan S November 10, 2011 8:49 PM
RE: Add Captcha In Sign in Portlet Puneet Upadhyay November 12, 2011 2:44 AM
RE: Add Captcha In Sign in Portlet Puneet Upadhyay November 13, 2011 10:30 PM
RE: Add Captcha In Sign in Portlet srikanth a November 14, 2011 3:47 AM
RE: Add Captcha In Sign in Portlet Puneet Upadhyay November 15, 2011 10:04 PM
RE: Add Captcha In Sign in Portlet srikanth a November 15, 2011 11:20 PM
RE: Add Captcha In Sign in Portlet Puneet Upadhyay November 16, 2011 12:31 AM
RE: Add Captcha In Sign in Portlet chirag @ India April 10, 2013 1:42 AM
RE: Add Captcha In Sign in Portlet mohammad azaruddin July 4, 2013 11:09 AM
RE: Add Captcha In Sign in Portlet chirag @ India July 4, 2013 11:24 PM
RE: Add Captcha In Sign in Portlet Manish Yadav July 5, 2013 12:01 AM
RE: Add Captcha In Sign in Portlet chirag @ India July 5, 2013 4:52 AM
RE: Add Captcha In Sign in Portlet parikshit sharma July 5, 2013 6:05 AM
RE: Add Captcha In Sign in Portlet Manish Yadav July 5, 2013 6:47 AM
RE: Add Captcha In Sign in Portlet chirag @ India July 5, 2013 10:13 PM
RE: Add Captcha In Sign in Portlet mohammad azaruddin July 5, 2013 12:28 AM
RE: Add Captcha In Sign in Portlet Szymon Gołębiewski November 14, 2011 2:44 AM
RE: Add Captcha In Sign in Portlet Puneet Upadhyay November 14, 2011 8:44 PM
RE: Add Captcha In Sign in Portlet Szymon Gołębiewski November 15, 2011 3:46 AM
RE: Add Captcha In Sign in Portlet Vlad Kuzmyk April 3, 2012 6:39 AM
RE: Add Captcha In Sign in Portlet Mustafa Yüceel April 9, 2013 4:40 AM
Automatyczna odpowiedź: [Liferay Forums][3. Development] RE: Add Captcha In Szymon Gołębiewski April 9, 2013 4:40 AM
Puneet Upadhyay
Add Captcha In Sign in Portlet
November 10, 2011 8:38 PM
Answer

Puneet Upadhyay

Rank: Regular Member

Posts: 234

Join Date: October 22, 2011

Recent Posts

Please tell me how to add captcha in sign in portlet.
Manikandan S
RE: Add Captcha In Sign in Portlet
November 10, 2011 8:49 PM
Answer

Manikandan S

Rank: Expert

Posts: 492

Join Date: September 15, 2010

Recent Posts

You can get it here blog

And you can get full coding here link
Puneet Upadhyay
RE: Add Captcha In Sign in Portlet
November 12, 2011 2:44 AM
Answer

Puneet Upadhyay

Rank: Regular Member

Posts: 234

Join Date: October 22, 2011

Recent Posts

Thanks Mani but i am unable to do this is sign in portlet.
will you please elaborate this???
Puneet Upadhyay
RE: Add Captcha In Sign in Portlet
November 13, 2011 10:30 PM
Answer

Puneet Upadhyay

Rank: Regular Member

Posts: 234

Join Date: October 22, 2011

Recent Posts

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???
Szymon Gołębiewski
RE: Add Captcha In Sign in Portlet
November 14, 2011 2:44 AM
Answer

Szymon Gołębiewski

Rank: Regular Member

Posts: 247

Join Date: June 8, 2009

Recent Posts

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
srikanth a
RE: Add Captcha In Sign in Portlet
November 14, 2011 3:47 AM
Answer

srikanth a

Rank: Regular Member

Posts: 142

Join Date: February 20, 2011

Recent Posts

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
Puneet Upadhyay
RE: Add Captcha In Sign in Portlet
November 14, 2011 8:44 PM
Answer

Puneet Upadhyay

Rank: Regular Member

Posts: 234

Join Date: October 22, 2011

Recent Posts

i am using 6.1 version.
Szymon Gołębiewski
RE: Add Captcha In Sign in Portlet
November 15, 2011 3:46 AM
Answer

Szymon Gołębiewski

Rank: Regular Member

Posts: 247

Join Date: June 8, 2009

Recent Posts

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
Puneet Upadhyay
RE: Add Captcha In Sign in Portlet
November 15, 2011 10:04 PM
Answer

Puneet Upadhyay

Rank: Regular Member

Posts: 234

Join Date: October 22, 2011

Recent Posts

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.
srikanth a
RE: Add Captcha In Sign in Portlet
November 15, 2011 11:20 PM
Answer

srikanth a

Rank: Regular Member

Posts: 142

Join Date: February 20, 2011

Recent Posts

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.
Puneet Upadhyay
RE: Add Captcha In Sign in Portlet
November 16, 2011 12:31 AM
Answer

Puneet Upadhyay

Rank: Regular Member

Posts: 234

Join Date: October 22, 2011

Recent Posts

Ok Sri. I try this
Vlad Kuzmyk
RE: Add Captcha In Sign in Portlet
April 3, 2012 6:39 AM
Answer

Vlad Kuzmyk

Rank: New Member

Posts: 10

Join Date: January 18, 2012

Recent Posts

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
RE: Add Captcha In Sign in Portlet
April 9, 2013 4:40 AM
Answer

Mustafa Yüceel

Rank: New Member

Posts: 1

Join Date: October 2, 2012

Recent Posts

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/
Szymon Gołębiewski
Automatyczna odpowiedź: [Liferay Forums][3. Development] RE: Add Captcha In
April 9, 2013 4:40 AM
Answer

Szymon Gołębiewski

Rank: Regular Member

Posts: 247

Join Date: June 8, 2009

Recent Posts

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
chirag @ India
RE: Add Captcha In Sign in Portlet
April 10, 2013 1:42 AM
Answer

chirag @ India

Rank: Regular Member

Posts: 129

Join Date: December 20, 2011

Recent Posts

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
mohammad azaruddin
RE: Add Captcha In Sign in Portlet
July 4, 2013 11:09 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 457

Join Date: September 17, 2012

Recent Posts

@chirag
Can you please share some hint or link ti create Captcha
chirag @ India
RE: Add Captcha In Sign in Portlet
July 4, 2013 11:24 PM
Answer

chirag @ India

Rank: Regular Member

Posts: 129

Join Date: December 20, 2011

Recent Posts

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
Manish Yadav
RE: Add Captcha In Sign in Portlet
July 5, 2013 12:01 AM
Answer

Manish Yadav

Rank: Expert

Posts: 385

Join Date: May 26, 2012

Recent Posts

Hi Chirag ,

You can use below code for refresh captcha using jquery.

SCRIPT
1
2<script>
3jQuery("#refreshCaptchaActivity").click(function() {
4     jQuery(".captcha").attr("src", jQuery(".captcha").attr("src")+"&force=" + new Date().getMilliseconds());
5     return false;
6});
7</script>



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


Please let me know if you require more inputs
Regards
Manish Banwari lal Yadav
mohammad azaruddin
RE: Add Captcha In Sign in Portlet
July 5, 2013 12:28 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 457

Join Date: September 17, 2012

Recent Posts

Hi try this recapcha..working on it
chirag @ India
RE: Add Captcha In Sign in Portlet
July 5, 2013 4:52 AM
Answer

chirag @ India

Rank: Regular Member

Posts: 129

Join Date: December 20, 2011

Recent Posts

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..

1jQuery("#refreshCaptchaActivity").click(function()
2        {
3    alert("hii");
4    jQuery(".captcha").attr("src", jQuery(".captcha").attr("src")+"&force=" + new Date().getMilliseconds());
5    return false;
6        });


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
parikshit sharma
RE: Add Captcha In Sign in Portlet
July 5, 2013 6:05 AM
Answer

parikshit sharma

Rank: Junior Member

Posts: 47

Join Date: October 18, 2012

Recent Posts

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.

1<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
Manish Yadav
RE: Add Captcha In Sign in Portlet
July 5, 2013 6:47 AM
Answer

Manish Yadav

Rank: Expert

Posts: 385

Join Date: May 26, 2012

Recent Posts

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
chirag @ India
RE: Add Captcha In Sign in Portlet
July 5, 2013 10:13 PM
Answer

chirag @ India

Rank: Regular Member

Posts: 129

Join Date: December 20, 2011

Recent Posts

hi manish,

thanks its working cheersemoticon