Foren

Create user and tagged to the role based on online parameter

LR BEGINNER, geändert vor 7 Jahren.

Create user and tagged to the role based on online parameter

New Member Beiträge: 24 Beitrittsdatum: 21.07.16 Neueste Beiträge
Hi All,

I'm using liferay 6.2 and i'm wondering wheher there's a way to create user and tagged to the role based on online parameter. For example, if user select "Buyer" role, then this user will be created in user_ table and tagged to "Buyer" role in users_roles. There can be more than 1 role.
Thanks in advance.
thumbnail
Samuel Kong, geändert vor 7 Jahren.

RE: Create user and tagged to the role based on online parameter

Liferay Legend Beiträge: 1902 Beitrittsdatum: 10.03.08 Neueste Beiträge
You can use the method UserLocalServiceUtil.addUser. There's a parameter for specifying the 'roleIds' parameter where you can specify the roles that the user should have.
LR BEGINNER, geändert vor 7 Jahren.

RE: Create user and tagged to the role based on online parameter

New Member Beiträge: 24 Beitrittsdatum: 21.07.16 Neueste Beiträge
Thanks Samuel.

I'm trying to use that method, but it throws error when triggering this line below:
UserLocalServiceUtil.addUser(user);

Attached is my file for reference. Any advise would be great. Thanks.
thumbnail
Samuel Kong, geändert vor 7 Jahren.

RE: Create user and tagged to the role based on online parameter

Liferay Legend Beiträge: 1902 Beitrittsdatum: 10.03.08 Neueste Beiträge
Don't use the addUser(User) method. Use the one with many parameters instead.
LR BEGINNER, geändert vor 7 Jahren.

RE: Create user and tagged to the role based on online parameter

New Member Beiträge: 24 Beitrittsdatum: 21.07.16 Neueste Beiträge
Thanks Samuel, i'm able to add it now using the method suggested by you.

UserLocalServiceUtil.addUser(0, companyId, true, null, null,
false, screenName, emailAddress, facebookId, openId,
themeDisplay.getLocale(), firstName, middleName, lastName, prefixId, suffixId,
(gender.equalsIgnoreCase("male")?true:false), calBday.get(Calendar.MONTH), calBday.get(Calendar.DAY_OF_MONTH),
calBday.get(Calendar.YEAR), jobTitle, new long[] {group.getGroupId()},
null, roleids, null, true, serviceContext);