掲示板

get logined user info in webcontent portlet?

thumbnail
14年前 に cometta cometta cometta によって更新されました。

get logined user info in webcontent portlet?

Regular Member 投稿: 109 参加年月日: 09/04/27 最新の投稿
may i know how to get user logined info in Web content portlet? i need these information to be pass to another web application through iframe.
thumbnail
14年前 に Auditya manikanta Vadrevu によって更新されました。

RE: get logined user info in webcontent portlet?

Liferay Master 投稿: 621 参加年月日: 08/05/06 最新の投稿
hi,

first add this to portal-ext.properties
journal.template.velocity.restricted.variables=    


then in your template,

#set ($userId = $getterUtil.getLong($request.remote-user))
 #set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
 #set($user = $userLocalService.getUserById($userId)) 


now you can access all the details of a user using $user like user.getFirstName() etc..,

With Regards,
V.Auditya.
thumbnail
14年前 に cometta cometta cometta によって更新されました。

RE: get logined user info in webcontent portlet?

Regular Member 投稿: 109 参加年月日: 09/04/27 最新の投稿
1. i tried on on page template and it work. but not in webcontent portlet .
2. how to use #set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService")) to check whether user belong to member of a group?


i try these



#set ($checkUserGroup = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
#set($usergroup = $checkUserGroup.getUserGroups($userId))



and i always get empty list [] , even though user belong to one of the group .. is this correct , way to get all groupname that user joined?
thumbnail
14年前 に Auditya manikanta Vadrevu によって更新されました。

RE: get logined user info in webcontent portlet?

Liferay Master 投稿: 621 参加年月日: 08/05/06 最新の投稿
hi,
try this...

#set ($userId = $getterUtil.getLong($request.remote-user))
#set ($userGroup = $serviceLocator.findService("com.liferay.portal.service.UserGroupLocalService"))
#set($ug = $userGroup.getUserUserGroups($userId))
#foreach($g in $ug)
{$g.getName()}
#end


With Regards,
V.Auditya.
thumbnail
14年前 に cometta cometta cometta によって更新されました。

RE: get logined user info in webcontent portlet?

Regular Member 投稿: 109 参加年月日: 09/04/27 最新の投稿
Auditya manikanta Vadrevu:
hi,
try this...

#set ($userId = $getterUtil.getLong($request.remote-user))
#set ($userGroup = $serviceLocator.findService("com.liferay.portal.service.UserGroupLocalService"))
#set($ug = $userGroup.getUserUserGroups($userId))
#foreach($g in $ug)
{$g.getName()}
#end


With Regards,
V.Auditya.



Thank you to you V. Auditya for prompt response. just to share with you my result. for $ug i always get [] (empty) while, when i use userTheme, to get user's groups. there is not problem. hmm. i think just use userTheme for this case. but i got no idea why UserGroupLocalService return [] cheers. have a nice days
14年前 に Life Ray によって更新されました。

RE: get logined user info in webcontent portlet?

New Member 投稿: 13 参加年月日: 08/10/14 最新の投稿
thanks for this - for me it works. but the funny thing is that the remote-user information is still available after the user logged out ?!?
I wanted to use this solution to hide content within a WebContent portlet if the current user is logged in or not - but now independently of the log-in state i have these information. do you have any idea how to figure out if a user is logged in within web-content template.

btw. the themeDisplay is not available within the cms velocity variables - so i cannot access to the isSignedIn method.

thx in advance.
thumbnail
14年前 に Auditya manikanta Vadrevu によって更新されました。

RE: get logined user info in webcontent portlet?

Liferay Master 投稿: 621 参加年月日: 08/05/06 最新の投稿
hi ray vin,

so the content is not updating .
have you unticked the Cacheable option in template. that may be the problem.


with Regards,
v.Auditya
thumbnail
14年前 に R charan によって更新されました。

RE: get logined user info in webcontent portlet?

Junior Member 投稿: 72 参加年月日: 08/10/28 最新の投稿
hi auditya,

yes, right. now its working fine after removing the cacheable option

thanx for solution.
14年前 に Ray Vin によって更新されました。

RE: get logined user info in webcontent portlet?

New Member 投稿: 13 参加年月日: 08/10/14 最新の投稿
Yes, now it works. Thanks a lot!
thumbnail
9年前 に michael hamlett によって更新されました。

RE: get logined user info in webcontent portlet?

Junior Member 投稿: 30 参加年月日: 13/05/23 最新の投稿
I am a complete newbie to Liferay
your instructions are completely unfollowable to me.

I added the code to the portal-ext.properties.
when you say add to template. what does that mean.
I found in my template directory a VM file and I added the code there since there were other SET statements.

now what.

I need to access the logged in screen name from the webcontent portlet.
specifically I want to create a hyper link (HREF) to another website page and pass the username.

ex (http://www.mysite.com/mypage.aspx?username=[liferay username]

thanks for your help.
thumbnail
14年前 に Kanakaraj Cheram によって更新されました。

RE: get logined user info in webcontent portlet?

New Member 投稿: 20 参加年月日: 08/04/08 最新の投稿
cometta cometta cometta:
may i know how to get user logined info in Web content portlet? i need these information to be pass to another web application through iframe.


Try this ...
Using theme display
u can get things regarding logged in user
...
User user=themeDisplay.getUser();

eg...

user.getScreenName();
user.getEmailAddress()
user.getCompanyId()
user.getOrganizations()
user.getUserGroups()
user.getUserId()