Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
How to add captcha for adding a post on message board Michał Drzewiecki December 17, 2013 4:18 AM
RE: How to add captcha for adding a post on message board Pankaj Kathiriya December 17, 2013 4:30 AM
RE: How to add captcha for adding a post on message board Michał Drzewiecki December 17, 2013 4:46 AM
RE: How to add captcha for adding a post on message board Michał Drzewiecki December 18, 2013 4:10 AM
RE: How to add captcha for adding a post on message board Pankaj Kathiriya December 18, 2013 11:26 PM
RE: How to add captcha for adding a post on message board Michał Drzewiecki December 19, 2013 2:22 AM
RE: How to add captcha for adding a post on message board Roshan Qureshi December 19, 2013 3:01 AM
RE: How to add captcha for adding a post on message board Pankaj Kathiriya December 19, 2013 3:22 AM
RE: How to add captcha for adding a post on message board Michał Drzewiecki December 23, 2013 6:26 AM
RE: How to add captcha for adding a post on message board James Falkner December 23, 2013 7:50 AM
RE: How to add captcha for adding a post on message board Michał Drzewiecki December 27, 2013 1:15 AM
RE: How to add captcha for adding a post on message board Pankaj Kathiriya December 30, 2013 12:38 AM
RE: How to add captcha for adding a post on message board James Falkner January 2, 2014 10:07 AM
RE: How to add captcha for adding a post on message board Michał Drzewiecki January 2, 2014 11:08 PM
RE: How to add captcha for adding a post on message board Roshan Qureshi December 18, 2013 4:16 AM
Michał Drzewiecki
How to add captcha for adding a post on message board
December 17, 2013 4:18 AM
Answer

Michał Drzewiecki

Rank: New Member

Posts: 16

Join Date: December 11, 2013

Recent Posts

Hello,

I have a requirement that would allow site administrator to configure captcha veryfication for post writing on a message board.
I couldn't find a plugin or any configuration option in message board that would allow me to add captcha, therefore I think that I would need to somehow add it myself.
Does anyone have any idea about how it could be achieved? Where I should start? Thanks in advance! emoticon
Pankaj Kathiriya
RE: How to add captcha for adding a post on message board
December 17, 2013 4:30 AM
Answer

Pankaj Kathiriya

Rank: Liferay Master

Posts: 671

Join Date: August 4, 2010

Recent Posts

Using plugin-hook, override jsp responsible for Add/Edit Message screen in Message Board and add captcha using liferay tag liferay-ui:captcha .

Also Override StrutsAction class responsible for Add/Edit Message in MessageBoard Portlet and before calling original struts-action, validate captcha string.

Refer to https://github.com/liferay/liferay-plugins/tree/master/hooks for initial help to start coding.

Hope this would help.

Regards,
Pankaj
Michał Drzewiecki
RE: How to add captcha for adding a post on message board
December 17, 2013 4:46 AM
Answer

Michał Drzewiecki

Rank: New Member

Posts: 16

Join Date: December 11, 2013

Recent Posts

Pankaj, thank you very much for your fast response! emoticon
It was very helpful. Now I know where to start. emoticon
Michał Drzewiecki
RE: How to add captcha for adding a post on message board
December 18, 2013 4:10 AM
Answer

Michał Drzewiecki

Rank: New Member

Posts: 16

Join Date: December 11, 2013

Recent Posts

I found where and how to change JSP via hook but I don't know which StrutsAction should I override and how to validate captcha string.

While I was trying to add StrutsAction Hook in liferay-hook.xml Overview mode I had to fill 2 fields:
Struts action path - I think that I could use "/message_boards/captcha"
and Struts Action Impl - I don't know what I could use here. According to IDE:
Select an existing struts path to override or specify a new one. Then select the struts action impl class. The impl class must implement either StrutsAction or StrutsPortletAction. StrutsAction is used for regular struts actions like /c/portal/update_password and StrutsPortletAction is used for those that are used from portlet


I tried to find in liferay source code any implementation of StrutsAction or StrutsPortletAction connected with captcha but I couldn't find anything. Could you provide me some hints about what I should do now?

Edit: I've found how to get captchaText and enteredCaptchaText >in this post<.
Unfortunately I still don't know how to plug it into StrutAction Hook.
Roshan Qureshi
RE: How to add captcha for adding a post on message board
December 18, 2013 4:16 AM
Answer

Roshan Qureshi

Rank: Regular Member

Posts: 144

Join Date: August 24, 2010

Recent Posts

Thanks Pankaj.
Informative answer.
Pankaj Kathiriya
RE: How to add captcha for adding a post on message board
December 18, 2013 11:26 PM
Answer

Pankaj Kathiriya

Rank: Liferay Master

Posts: 671

Join Date: August 4, 2010

Recent Posts

Michal,
You would have to override struts-action for /message_boards/edit_message and/or /message_boards/edit_discussion with having your custom action class.

In this action class before calling originalStrutsAction's processAction, validate captcha.

For how to validate captcha, you can refer code of com.liferay.portlet.login.action.CreateAccountAction.java i.e.
1CaptchaUtil.check(actionRequest);


Regards,
Pankaj K
Michał Drzewiecki
RE: How to add captcha for adding a post on message board
December 19, 2013 2:22 AM
Answer

Michał Drzewiecki

Rank: New Member

Posts: 16

Join Date: December 11, 2013

Recent Posts

In my understanding the overriding should be achieved by using hooks, am I correct?

I've tried adding a hook for EditMessageAction but IDE prevents me from doing this with following error:



Should I select some other class? Or maybe my entire approach with using hooks is wrong?
Roshan Qureshi
RE: How to add captcha for adding a post on message board
December 19, 2013 3:01 AM
Answer

Roshan Qureshi

Rank: Regular Member

Posts: 144

Join Date: August 24, 2010

Recent Posts

Hi Michale,

Follow this link. Hope this will help you.

https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/lp-6-1-dgen06-overriding-and-adding-struts-actions-0

Regards,
Roshan Qureshi
Pankaj Kathiriya
RE: How to add captcha for adding a post on message board
December 19, 2013 3:22 AM
Answer

Pankaj Kathiriya

Rank: Liferay Master

Posts: 671

Join Date: August 4, 2010

Recent Posts

Michał Drzewiecki
In my understanding the overriding should be achieved by using hooks, am I correct?

Yes

Michał Drzewiecki
Should I select some other class?


Yes, you have to extend BaseStrutsPortletAction or StrutsPortletAction, please refer the link for code.

Michał Drzewiecki
Or maybe my entire approach with using hooks is wrong?

You can implement this solution using hook
Michał Drzewiecki
RE: How to add captcha for adding a post on message board
December 23, 2013 6:26 AM
Answer

Michał Drzewiecki

Rank: New Member

Posts: 16

Join Date: December 11, 2013

Recent Posts

@Roshan, @Pankaj Thank you for your help. I still didn't manage to fully implement captcha but your advices were great help.

As I was reading existing code, I've found in edit_message.jsp following code fragment:

1<c:if test="<%= (message == null) && PropsValues.CAPTCHA_CHECK_PORTLET_MESSAGE_BOARDS_EDIT_MESSAGE %>">
2    <portlet:resourceURL var="captchaURL">
3        <portlet:param name="struts_action" value="/message_boards/captcha" />
4    </portlet:resourceURL>
5
6    <liferay-ui:captcha url="<%= captchaURL %>" />
7</c:if>


For me it looks like captcha functionality is already implemented for creating/editing posts but it needs to be first enabled somewhere in configuration. Am I right about this?

I've thought that maybe this line in portal.properties might be responsible for showing captcha on the screen:

1captcha.check.portlet.message_boards.edit_message=true


but unfortunately it had no effect...
James Falkner
RE: How to add captcha for adding a post on message board
December 23, 2013 7:50 AM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1362

Join Date: September 17, 2010

Recent Posts

Michał Drzewiecki:

For me it looks like captcha functionality is already implemented for creating/editing posts but it needs to be first enabled somewhere in configuration. Am I right about this?

I've thought that maybe this line in portal.properties might be responsible for showing captcha on the screen:

1captcha.check.portlet.message_boards.edit_message=true


but unfortunately it had no effect...


You are correct, that configuration option should turn on a Captcha for creating/editing posts - it seems to work for me with 6.2 CE GA1 - what version of Liferay are you using? Any errors in the log?
Michał Drzewiecki
RE: How to add captcha for adding a post on message board
December 27, 2013 1:15 AM
Answer

Michał Drzewiecki

Rank: New Member

Posts: 16

Join Date: December 11, 2013

Recent Posts

I'm also using liferay-6.2.0-ce-ga1...
I thought that maybe my environment got corrupted so I installed it from the scratch on another machine and tested it there. Unfortunately without success.

Hook is deployed without any errors:
108:42:59,284 INFO  [ContainerBackgroundProcessor[StandardEngine[Catalina]]][HookHotDeployListener:687] Registering hook for msgboard-hook
2Loading file:/home/disper/dev/tools/liferay-portal-6.2.0-ce-ga1/tomcat-7.0.42/temp/10-msgboard-hook/WEB-INF/classes/portal.properties
308:42:59,299 INFO  [ContainerBackgroundProcessor[StandardEngine[Catalina]]][HookHotDeployListener:814] Hook for msgboard-hook is available for use
4Dec 27, 2013 8:42:59 AM org.apache.catalina.core.StandardContext reload
5INFO: Reloading Context with name [/msgboard-hook] is completed


Maybe I forgot to do something? To add captcha property I've done following things:

  1. Created new hook plugin project
  2. Created portal.properties file in my docroot/WEB-INF/src which is in my classpath
  3. Added "captcha.check.portlet.message_boards.edit_message=true" to portal.properties
  4. Updated liferay-hook.xml with following entry: <portal-properties>portal.properties</portal-properties>
  5. Deployed hook to the liferay server


I've attached my project file...
Attachments: msgboard-hook.zip (7.6k)
Pankaj Kathiriya
RE: How to add captcha for adding a post on message board
December 30, 2013 12:38 AM
Answer

Pankaj Kathiriya

Rank: Liferay Master

Posts: 671

Join Date: August 4, 2010

Recent Posts

All portal properties can not be overridden with hook feature.

You can find out supported properties those can be overriden in dtd file :

liferay-portal-src-6.2.0-ce-ga1\definitions\liferay-hook_6_2_0.dtd

To achieve captcha on message board edit screen, you have to provide

captcha.check.portlet.message_boards.edit_message=true

in portal-ext.properties file. You have to keep portal-ext.properties file parallel to tomcat folder.

I have verified this, its working fine.

Regards,
James Falkner
RE: How to add captcha for adding a post on message board
January 2, 2014 10:07 AM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1362

Join Date: September 17, 2010

Recent Posts

Pankaj Kathiriya:
All portal properties can not be overridden with hook feature.

You can find out supported properties those can be overriden in dtd file :

liferay-portal-src-6.2.0-ce-ga1\definitions\liferay-hook_6_2_0.dtd

To achieve captcha on message board edit screen, you have to provide

captcha.check.portlet.message_boards.edit_message=true

in portal-ext.properties file. You have to keep portal-ext.properties file parallel to tomcat folder.

I have verified this, its working fine.

Regards,


Also, be aware that you can override portal properties WITHOUT creating any hook at all. Simply place a file called portal-ext.properties into one of two locations (either your Liferay Home directory, which is the directory where you find your app server, 'data', 'deploy', and other folders), OR in the classpath of the portal (typically in something like tomcat-xx.xx.xx/webapps/ROOT/WEB-INF/classes). I recommend the Liferay Home directory, because the other directory will be wiped out if you re-deploy the base Liferay WAR file.
Michał Drzewiecki
RE: How to add captcha for adding a post on message board
January 2, 2014 11:08 PM
Answer

Michał Drzewiecki

Rank: New Member

Posts: 16

Join Date: December 11, 2013

Recent Posts

James Falkner:

Also, be aware that you can override portal properties WITHOUT creating any hook at all. Simply place a file called portal-ext.properties into one of two locations (either your Liferay Home directory, which is the directory where you find your app server, 'data', 'deploy', and other folders), OR in the classpath of the portal (typically in something like tomcat-xx.xx.xx/webapps/ROOT/WEB-INF/classes). I recommend the Liferay Home directory, because the other directory will be wiped out if you re-deploy the base Liferay WAR file.


I'll keep it in mind! Thank you emoticon