Message Boards
Unable to get Logged in userId in post login action using hook.
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.
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
Your help has arrived. Check this out !
https://www.liferay.com/community/forums/-/message_boards/message/11258859
https://www.liferay.com/community/forums/-/message_boards/message/11258859
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.
Even though method sounds like it will return name but actually it will return userid in string format.
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.
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();
As per my previous link, it could have been done by PortalUtil.getUser(req).getUserId();
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.
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?
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 Postsronak vora:
In 7.1, rather implement a Lifecycle Action.
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?
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