Message Boards

Unable to get Logged in userId in post login action using hook.

thumbnail
Omkar Khandare, modified 11 Years ago.

Unable to get Logged in userId in post login action using hook.

Junior Member Posts: 49 Join Date: 3/7/12 Recent Posts
I am using post login hook to redirect to my custom page on certain condition.
I have followed as same as example given in Liferay docs for hook.
except i am calling it as post login by adding following in portal.properties file.

login.events.post=com.sa.postlogin.ConditionCheckAction

& in action.
User user = ((ThemeDisplay) arg0.getAttribute(WebKeys.THEME_DISPLAY)).getUser();
long userId=user.getUserId();
(above line gives NullPointer Exception)

It calls my action but i unable to get current logged in user's userId in it.

How i can able to get it.??

Plz Help.
Siby Mathew, modified 11 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Expert Posts: 268 Join Date: 3/4/11 Recent Posts
thumbnail
Jitendra Rajput, modified 11 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Liferay Master Posts: 875 Join Date: 1/7/11 Recent Posts
You can also use PrincipalThreadLocal.getName() .
Even though method sounds like it will return name but actually it will return userid in string format.
thumbnail
Omkar Khandare, modified 11 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Junior Member Posts: 49 Join Date: 3/7/12 Recent Posts
Thanks I did it by,

Long userId= Long.parseLong(arg0.getRemoteUser());

It works fine.

Thanks.
Siby Mathew, modified 11 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Expert Posts: 268 Join Date: 3/4/11 Recent Posts
Hi Omkar,
As per my previous link, it could have been done by PortalUtil.getUser(req).getUserId();
thumbnail
Jaynil A Bagdai, modified 11 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Regular Member Posts: 119 Join Date: 3/3/12 Recent Posts
Omkar,

You should use the solution which has been provided by Siby.
The one which you are using is not reliable solution.
ronak vora, modified 3 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Junior Member Posts: 25 Join Date: 9/26/18 Recent Posts
can we override login.events.pre and  login.events.post  into hook for liferay 7.1 CE OR anythig else for Getting login User information using hook?
thumbnail
Olaf Kock, modified 3 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
ronak vora:

can we override login.events.pre and  login.events.post  into hook for liferay 7.1 CE OR anythig else for Getting login User information using hook?
In 7.1, rather implement a Lifecycle Action.
ronak vora, modified 3 Years ago.

RE: Unable to get Logged in userId in post login action using hook.

Junior Member Posts: 25 Join Date: 9/26/18 Recent Posts
Ok Thank you  Olaf kock it helps lot