Fórum

get logined user info in webcontent portlet?

thumbnail
cometta cometta cometta, modificado 14 Anos atrás.

get logined user info in webcontent portlet?

Regular Member Postagens: 109 Data de Entrada: 27/04/09 Postagens Recentes
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
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
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
cometta cometta cometta, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

Regular Member Postagens: 109 Data de Entrada: 27/04/09 Postagens Recentes
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
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
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
cometta cometta cometta, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

Regular Member Postagens: 109 Data de Entrada: 27/04/09 Postagens Recentes
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
Life Ray, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

New Member Postagens: 13 Data de Entrada: 14/10/08 Postagens Recentes
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
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
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
R charan, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

Junior Member Postagens: 72 Data de Entrada: 28/10/08 Postagens Recentes
hi auditya,

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

thanx for solution.
Ray Vin, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

New Member Postagens: 13 Data de Entrada: 14/10/08 Postagens Recentes
Yes, now it works. Thanks a lot!
thumbnail
michael hamlett, modificado 9 Anos atrás.

RE: get logined user info in webcontent portlet?

Junior Member Postagens: 30 Data de Entrada: 23/05/13 Postagens Recentes
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
Kanakaraj Cheram, modificado 14 Anos atrás.

RE: get logined user info in webcontent portlet?

New Member Postagens: 20 Data de Entrada: 08/04/08 Postagens Recentes
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()