Foren
How to assign a site programmatically for user
Siraj Choudhary, geändert vor 10 Jahren.
How to assign a site programmatically for user
Junior Member Beiträge: 31 Beitrittsdatum: 13.11.13 Neueste Beiträge
Hi,
I am creating user account in liferay programmatically. While creating a user itself i want assign a site for that user.
Let's say for example I am creating an account as test@liferay.com, and there is site which is already available in portal let's say it is "Trade Licence". I want to assign this Trade Licence to user test. So that when he logs in directly it should redirect him to "Trade Licence" site.
I tried it i am getting siteId from groups table bellow is my code to get site id. but i am not getting where to use it and how to assign it.
Thank you
Siraj
I am creating user account in liferay programmatically. While creating a user itself i want assign a site for that user.
Let's say for example I am creating an account as test@liferay.com, and there is site which is already available in portal let's say it is "Trade Licence". I want to assign this Trade Licence to user test. So that when he logs in directly it should redirect him to "Trade Licence" site.
I tried it i am getting siteId from groups table bellow is my code to get site id. but i am not getting where to use it and how to assign it.
List<group> groupList=GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());
for(Group group : groupList){
if(group.getName().equalsIgnoreCase("Trade Licence")){
siteId=group.getGroupId();
}
}</group>
Thank you
Siraj
Tanaji Londhe, geändert vor 10 Jahren.
RE: How to assign a site programmatically for user
Regular Member Beiträge: 194 Beitrittsdatum: 25.04.12 Neueste Beiträge
If you know exact site name then their is no need iterate all sites, you just through API for GroupLocalServiceUtil
Group group = GroupLocalServiceUtil.getGroup(companyId, site_name); this will return group.
To add any group to particular user just write following code depending on your requirement.
UserUtil.addGroup(pk, group); or UserUtil.addGroup(pk, groupPK);
Group group = GroupLocalServiceUtil.getGroup(companyId, site_name); this will return group.
To add any group to particular user just write following code depending on your requirement.
UserUtil.addGroup(pk, group); or UserUtil.addGroup(pk, groupPK);
Pankaj Kathiriya, geändert vor 10 Jahren.
RE: How to assign a site programmatically for user
Liferay Master Beiträge: 722 Beitrittsdatum: 05.08.10 Neueste Beiträge
Use
to assign group membership to user.
Regards
UserLocalServiceUtil.addGroupUser(long groupId,long userId)
or UserLocalServiceUtil.addGroupUser(long groupId,User user)
to assign group membership to user.
Regards
Siraj Choudhary, geändert vor 10 Jahren.
RE: How to assign a site programmatically for user
Junior Member Beiträge: 31 Beitrittsdatum: 13.11.13 Neueste Beiträge
okey thank you