Fórum

create new user can site assign programmatically ????

Eswaran R, modificado 9 Anos atrás.

create new user can site assign programmatically ????

Junior Member Postagens: 82 Data de Entrada: 29/12/14 Postagens Recentes
Hi friends....

i am create new user via api using ...
but not assign site
how to assign site



String firstName= request.getParameter("fn");
String lastName =request.getParameter("ln");
String password1= request.getParameter("pw1");
String password2 = request.getParameter("pw2");

Date date=new Date();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setUuid(UUID.randomUUID().toString());
serviceContext.setCreateDate(date);
serviceContext.setModifiedDate(date);

long creatorUserId=0;
boolean autoPassword=false;
boolean autoScreenName=false;
boolean male=true;
boolean sendEmail = false;
int prefixId=1;
int suffixId=1;
int birthdayMonth=1;
int birthdayDay=9;
int birthdayYear=1991;
String jobTitle="";
long[] groupIds = null;
long[] organizationIds =null;
long[] userGroupIds = null;
long facebookId=0;
String openId="";
Locale locale=LocaleUtil.getDefault();
Role rolePu = RoleLocalServiceUtil.getRole(companyId, RoleConstants.POWER_USER);
long[] roleIds= {rolePu.getRoleId()};
User users43=UserLocalServiceUtil.addUserWithWorkflow(creatorUserId, companyId, autoPassword, password1,
password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName,
"", lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

organization create a new site
long[] organizationIds ={15626};

but i want site create for new user

long[] site= null;
eg
long[] groupIds = {12352}; //its correct????

thanks...

kindly help me....

Regards..
Eswaran R
Dipti Atkotiya, modificado 9 Anos atrás.

RE: create new user can site assign programmatically ????

New Member Postagens: 10 Data de Entrada: 09/01/15 Postagens Recentes
Hi Eswaran,
Use
UserLocalServiceUtil.addGroupUser(long groupId,long userId)
or
UserLocalServiceUtil.addGroupUser(long groupId,User user)

to assign group membership to user

and use below method for create as site
GroupServiceUtil.addGroup(long liveGroupId, String name, String description, int type, String friendlyURL, boolean site, boolean active, ServiceContext serviceContext)

Thanks,
Dipti Atkotiya
Eswaran R, modificado 9 Anos atrás.

RE: create new user can site assign programmatically ????

Junior Member Postagens: 82 Data de Entrada: 29/12/14 Postagens Recentes
Hi Dipti Atkotiya,,

thanks for reply ...

i am not create Group...
only create add user ...

so add user can site assign programmatically...??

thanks...

Regards..
Eswaran R
Vishal Patel, modificado 9 Anos atrás.

RE: create new user can site assign programmatically ????

Junior Member Postagens: 83 Data de Entrada: 24/11/14 Postagens Recentes
Hi,

You can your group id to array when creating user.

long[] groupIds = null; You can add your group id here like . long[] groupIds = {101010,101111}.


Also, The method which Dipti has mentioned is nor used for creating USERGROUP.

It is using to assigning any Group (SITE) to any user. So understand difference first!


Hope this will help you!
thumbnail
Jan Geißler, modificado 9 Anos atrás.

RE: create new user can site assign programmatically ????

Liferay Master Postagens: 735 Data de Entrada: 05/07/11 Postagens Recentes
If I understand you correct, you want to create a new User via the API and after the creation of the user, you want to assign him a default template, is that correct?
If so, there is one build in possibility, and one you have to code a little.
First one would be:
Liferay can assign Site Templates to UserGroups. So you could setup the portal in a way, where all new User get membership in a UserGroup on creation of the User, and assign a Site template to this UserGroup. The drawback is (at least with 6.1 ga2, but I don't know if the behavior is any different in later versions) that via this Setup, subpages will not get assigned correctly. Subpages will appear in the first level of the sitemap. Not as Subpages of Level 1 pages.

Second one:
https://www.liferay.com/de/community/forums/-/message_boards/message/18392329
this should help you getting on the right track. Copy and paste the code from SitesUtil (at least the relevant part) and include it in your class where you want to call it. But remember, that you have to give permission to the User, which is triggering the template assignment,.

Regards
Jan