Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
creating new user via API Marian Rosko April 3, 2009 5:50 AM
RE: creating new user via API Luc Pons May 20, 2009 12:51 AM
RE: creating new user via API Ahmed Hasan May 20, 2009 4:22 AM
RE: creating new user via API Ayaz Pasha May 20, 2009 5:11 AM
RE: creating new user via API Ayaz Pasha May 20, 2009 5:35 AM
RE: creating new user via API Juan M. Gomez June 24, 2009 10:42 AM
RE: creating new user via API Amos Fong June 24, 2009 10:46 AM
RE: creating new user via API Juan M. Gomez June 24, 2009 3:04 PM
RE: creating new user via API Amos Fong September 10, 2009 3:43 PM
RE: creating new user via API Anonymous November 23, 2009 7:06 AM
RE: creating new user via API Man V K December 9, 2009 12:49 AM
RE: creating new user via API Shankar Baba March 30, 2013 4:13 AM
RE: creating new user via API li guicheng August 9, 2010 6:10 PM
RE: creating new user via API Suresh Chinna Pillai February 14, 2011 12:55 AM
RE: creating new user via API Siddhartha Bera February 15, 2011 11:21 AM
RE: creating new user via API Suresh Chinna Pillai February 16, 2011 7:45 AM
RE: creating new user via API RathnaDevi Chellaiah April 2, 2012 2:51 AM
RE: creating new user via API leo Hudson January 22, 2014 5:31 AM
RE: creating new user via API RathnaDevi Chellaiah March 30, 2012 6:50 AM
RE: creating new user via API David H Nebinger March 30, 2012 7:08 AM
RE: creating new user via API piyush liferay January 31, 2013 5:50 AM
RE: creating new user via API Shankar Baba March 28, 2013 4:28 AM
RE: creating new user via API Pepe Laberta November 5, 2010 8:04 AM
RE: creating new user via API Rajesh Chaurasia April 2, 2012 9:19 AM
RE: creating new user via API Rajesh Chaurasia April 2, 2012 9:24 AM
RE: creating new user via API saritha reddy June 30, 2014 4:54 AM
RE: creating new user via API David H Nebinger June 30, 2014 5:28 AM
Marian Rosko
creating new user via API
April 3, 2009 5:50 AM
Answer

Marian Rosko

Rank: New Member

Posts: 1

Join Date: April 3, 2009

Recent Posts

Hello everybody,

I am trying to create a new user via liferay API. The only way how I could create a user who was able to log in into the portal, was to repeat the steps form the create.sql script.

1) creating a new user: User user = UserLocalServiceUtil.createUser(userId);
2) setting properties for this user (password, companyId, screenName, active,.... )
3) creating corresponding contact: Contact contact = ContactLocalServiceUtil.createContact(contactId);
4) setting contact's properties (userId, accountId,...)
5) adding user: UserLocalServiceUtil.addUser(user);
6) adding contact: ContactLocalServiceUtil.addContact(contact);
7) adding user to the group: UserUtil.addGroups(userId, grpIds);
8) adding user to the organization: UserUtil.addOrganizations(userId, orgIds);
9) adding user roles: UserUtil.addRoles(id, roleIds);
10)creating group: GroupLocalServiceUtil.createGroup(groupId);
11)setting properties for the group
12)creating layout sets: LayoutSetLocalServiceUtil.createLayoutSet(layoutId);
13)setting propeties for the sets
14)adding group : GroupLocalServiceUtil.addGroup(group);
15)adding layout sets: LayoutSetLocalServiceUtil.addLayoutSet(ls1);

Isnt there a simpler solution which creates a liferay user with all (default) required dependecies/roles/groups?

Thanks in advance,
Marian
Luc Pons
RE: creating new user via API
May 20, 2009 12:51 AM
Answer

Luc Pons

Rank: Junior Member

Posts: 70

Join Date: December 3, 2008

Recent Posts

Here is a method i wrote :


 1public static User addUser(String firstName, String lastName, String email, String password, String screenName) throws CantAddUserException {
 2        try {
 3            
 4
 5            long[] emptyLong = {};
 6            User user = UserLocalServiceUtil.addUser(
 7                    new Long(Constants.ADMIN_ID) /*long creatorUserId*/,
 8                    Constants.COMP_ID /*long companyId*/,
 9                    false /*boolean autoPassword*/,
10                    password /*String password1*/,
11                    password /*String password2*/,
12                    false /*boolean autoScreenName*/,
13                    screenName /* String screenName*/,
14                    email /*String emailAddress*/,
15                    new Locale("fr") /*Locale locale*/,
16                    firstName /*String firstName*/,
17                    null /*String middleName*/,
18                    lastName /*String lastName*/,
19                    0/*int prefixId*/,
20                    0 /*int suffixId*/,
21                    false /*boolean male*/,
22                    1 /*int birthdayMonth*/,
23                    1 /*int birthdayDay*/,
24                    2000 /*int birthdayYear*/,
25                    null /*String jobTitle*/,
26                    emptyLong /*long[] organizationIds*/,
27                    false /*boolean sendEmail*/);
28
29            return user;
30
31        } catch (Exception e) {
32            throw new CantAddUserException(e);
33        }
34    }
Ahmed Hasan
RE: creating new user via API
May 20, 2009 4:22 AM
Answer

Ahmed Hasan

Rank: Expert

Posts: 304

Join Date: April 13, 2007

Recent Posts

Yes, this is the right approach to create a new user using the local service api.

For the unique userId you have to get it as below.

long userId = CounterLocalServiceUtil.increment();

The rest of the code is fine.

For any help feel free to contact me,

Ahmed Hasan
CTO, TransIT mPower Labs (P) Ltd.
info@mpowerglobal.com
mPower Global Inc.
A Liferay expert company.
Ayaz Pasha
RE: creating new user via API
May 20, 2009 5:11 AM
Answer

Ayaz Pasha

Rank: Junior Member

Posts: 78

Join Date: August 1, 2008

Recent Posts

I have a doubt, is it mandatory to pass the organizationIds as a value? Can it be an empty long[ ]? In short, is it necessary to have an Organization prior to create new user via API? But I can find that a new user can be created manually though he doesn't belong to any organization.

Hope what I am asking is clear?

Thanks !
Ayaz Pasha
RE: creating new user via API
May 20, 2009 5:35 AM
Answer

Ayaz Pasha

Rank: Junior Member

Posts: 78

Join Date: August 1, 2008

Recent Posts

The response for my previous query is yes we can create user via API by passing all the ids(such as groupIds, organizationIds, roleIds, userGroupIds) as an empty long [ ] untill it requires.
Juan M. Gomez
RE: creating new user via API
June 24, 2009 10:42 AM
Answer

Juan M. Gomez

Rank: Junior Member

Posts: 69

Join Date: November 7, 2007

Recent Posts

Hello, i have been able to create a new User using the following code..
 1long userId = CounterLocalServiceUtil.increment();
 2            User userToCreate = UserUtil.create(userId);
 3            userToCreate.setFirstName(firstName);
 4            userToCreate.setLastName(lastName);
 5            userToCreate.setEmailAddress(email);
 6            userToCreate.setPassword(password);
 7            userToCreate.setScreenName(screenName);
 8            userToCreate.setActive(true);
 9            userToCreate.setCreateDate(new Date());
10            userToCreate.setGreeting("Hi " + screenName);
11            userToCreate.setJobTitle(job_title);
12            userToCreate.setLanguageId(languageId);
13            userToCreate.setMiddleName(middleName);
14
15            User createdUser = UserLocalServiceUtil.addUser(userToCreate);


The user is persisted on liferay database with all the data i have passed.. but I still cannot login with it, and the User doesn't appear on the Users admin list. What is missing or what am I doing wrong?

I'm using Liferay 5.2.3.

Thanks in advance,
Juan M. Gomez



EDIT: The same happens with organizations.. i successfully create both the organization and the related group from the API, but i can't use them from the Portal.
Amos Fong
RE: creating new user via API
June 24, 2009 10:46 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1844

Join Date: October 7, 2008

Recent Posts

Hi Juan,

Try calling this afterward:

1        try {
2            UserIndexer.updateUser(user);
3        }
4        catch (SearchException se) {
5            _log.error("Indexing " + userId, se);
6        }
Juan M. Gomez
RE: creating new user via API
June 24, 2009 3:04 PM
Answer

Juan M. Gomez

Rank: Junior Member

Posts: 69

Join Date: November 7, 2007

Recent Posts

Hi Amos,

I had to import the portal-impl.jar into my project to use that method.. but after that everything worked perfectly.
Thank you.

Is there any similar method for Organizations??
Thanks again.


Juan M. Gomez
Amos Fong
RE: creating new user via API
September 10, 2009 3:43 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1844

Join Date: October 7, 2008

Recent Posts

Juan,

Sorry for late response, organizations are not indexed so no.
Anonymous
RE: creating new user via API
November 23, 2009 7:06 AM
Answer

Anonymous

I did:

long userId = CounterLocalServiceUtil.increment();
System.out.println(userId);

and I got some error. Someone could tell me what I did wrong do?

java.lang.NullPointerException
at com.liferay.counter.service.CounterLocalServiceUtil.increment(CounterLocalServiceUtil.java:42)
Man V K
RE: creating new user via API
December 9, 2009 12:49 AM
Answer

Man V K

Rank: Regular Member

Posts: 139

Join Date: December 4, 2007

Recent Posts

Hi,

I have created the user using the above code, it works fine, I checked the user table, it created the record. but i tried to enter with that user id and password but always get an error like this "You have entered invalid data. Please try again."

Any suggession please.

thanks
Vin
li guicheng
RE: creating new user via API
August 9, 2010 6:10 PM
Answer

li guicheng

Rank: Junior Member

Posts: 25

Join Date: March 28, 2010

Recent Posts

Anonymous:
I did:

long userId = CounterLocalServiceUtil.increment();
System.out.println(userId);

and I got some error. Someone could tell me what I did wrong do?

java.lang.NullPointerException
at com.liferay.counter.service.CounterLocalServiceUtil.increment(CounterLocalServiceUtil.java:42)


Could you tell me the solution if you get it through?
thank you

li_guicheng@hotmail.com
Pepe Laberta
RE: creating new user via API
November 5, 2010 8:04 AM
Answer

Pepe Laberta

Rank: New Member

Posts: 7

Join Date: May 12, 2010

Recent Posts

Hi, I have Liferay 5.2.3 and I have tried the following code (firstly in the doView method directly to test it). Its deploys without errors but when I launch the portlet it throws the following error:

com.liferay.portal.kernel.dao.orm.ormexception: could not execute jdbc batch update


long userId = CounterLocalServiceUtil.increment();
User userToCreate = UserUtil.create(userId);

userToCreate.setFirstName("Test Name");
userToCreate.setLastName("Test Last Name");
userToCreate.setEmailAddress("test@liferay.com");
userToCreate.setPassword("password");
userToCreate.setScreenName("Test Name");
userToCreate.setActive(true);
userToCreate.setCreateDate(new Date());
userToCreate.setGreeting("Hi Test Name");
userToCreate.setJobTitle("Job Test");
userToCreate.setLanguageId("en_US");
userToCreate.setMiddleName("Test");

User createdUser = UserLocalServiceUtil.addUser(userToCreate);

try {
UserIndexer.updateUser(createdUser);
}
catch (SearchException se) {
_log.error("Indexing " + userId, se);
}


What can I do to solve the problem?

Also, I am not sure if the installed liferay is using HSQL or MySQL. I have MySQL installed but I have not modified portal-ext.properties (I havent got it in the tomcat folder and I have not modified portal-imp.jar).

Thanks a lot.
Suresh Chinna Pillai
RE: creating new user via API
February 14, 2011 12:55 AM
Answer

Suresh Chinna Pillai

Rank: New Member

Posts: 16

Join Date: February 13, 2011

Recent Posts

Hi,
I am new to Liferay environment.I am creating a User management in Liferay with the API. but it throws the following Exception.
06:59:22,671 ERROR [JDBCExceptionReporter:101] ORA-00001: unique constraint (EBMS.IX_5ADBE171) violated

com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update



That constraint was set to the contactId of the User_ table.I created a contact of my own(manually)
and then executed the application the new user was added to the database.
1) The Process of creating the contactId of our own is good(or)not.If this process is bad.How can we overcome this problem?

and the user details was not displayed in the User list page of Liferay.As you mentioned in this forum append the following code.
1
2try {
32            UserIndexer.updateUser(user);
43        }
54        catch (SearchException se) {
65            _log.error("Indexing " + userId, se);
76        }

and we have to import the import "portal-impl.jar". I imported that jar.then it shows the error that "the method updateUser(User) is undefined for the type UserIndexer".How can I solve this one..?Where can I get the correct jar file..?
Pls help me..
I am Using Liferay 6.0.5 bundled with Tomcat.
Siddhartha Bera
RE: creating new user via API
February 15, 2011 11:21 AM
Answer

Siddhartha Bera

Rank: New Member

Posts: 2

Join Date: February 4, 2011

Recent Posts

IndexerRegistryUtil.register(new UserIndexer()); - In Liferay 6.0.5



You can do others too ....

IndexerRegistryUtil.register(new BookmarksIndexer());
IndexerRegistryUtil.register(new DLIndexer());
IndexerRegistryUtil.register(new IGIndexer());
IndexerRegistryUtil.register(new MBIndexer());
IndexerRegistryUtil.register(new AssetIndexer());
IndexerRegistryUtil.register(new JournalIndexer());
Suresh Chinna Pillai
RE: creating new user via API
February 16, 2011 7:45 AM
Answer

Suresh Chinna Pillai

Rank: New Member

Posts: 16

Join Date: February 13, 2011

Recent Posts

Hi friend,
Thank you for your quick reply. I found the solution for this issue. I use "UserLocalServiceUtil.addUser(long creatorUserId, long companyId, boolean autoPassword,
String password1, String password2, boolean autoScreenName,
String screenName, String emailAddress, long facebookId, String openId,
Locale locale, String firstName, String middleName, String lastName,
int prefixId, int suffixId, boolean male, int birthdayMonth,
int birthdayDay, int birthdayYear, String jobTitle, long[] groupIds,
long[] organizationIds, long[] roleIds, long[] userGroupIds,
boolean sendEmail, ServiceContext serviceContext)"
method.

It works fine.

Can you have any idea about how to add the user to a group..?

Thanks in advance..

-Suresh.
RathnaDevi Chellaiah
RE: creating new user via API
March 30, 2012 6:50 AM
Answer

RathnaDevi Chellaiah

Rank: Junior Member

Posts: 29

Join Date: March 26, 2012

Recent Posts

hi
i need ur help....am facing an issue regarding the creation of user using user form data.. my scenario is i have to create a registration form that is used by service builder and based on that it stores the value into db(lportel).. at the same time the value in the form should create a user into the liferay user table.
i have achieved upto storing of db.. but facing issue with creating user.. the form data is not fetched and stored into the predefined attributes of userlocalservice..


public void processAction(ActionRequest request,ActionResponse response) {

try {
long userId=CounterLocalServiceUtil.increment();
User user=UserLocalServiceUtil.createUser(userId);
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long creatorId=0;
long companyId = themeDisplay.getCompanyId();
user.setCompanyId(companyId);
boolean autoPassword = true;

String password1 = "";
user.setPassword(password1);
String password2 = "";
user.setPassword(password2);
boolean autoScreenName = true;
String screenName = "MyProfile1";
user.setScreenName(screenName);
String compemail = request.getParameter("cemail");// from the view.jsp page

user.setEmailAddress(compemail);
long facebookId = 0;
user.setFacebookId(facebookId);
String openId = "";
user.setOpenId(openId);
// Locale locale = themeDisplay.getLocale();
String firstName = request.getParameter("fname");// from the view.jsp page
user.setActive(true);
user.setFirstName(firstName);

String middleName = "";
String lastName = request.getParameter("lname");// from the view.jsp page
user.setLastName(lastName);
int prefixId = 0;
int suffixId = 0;
boolean male = true;
int birthdayMonth = 0;
int birthdayDay = 0;
int birthdayYear = 0;
String designation =request.getParameter("designation");// from the view.jsp page
user.setJobTitle(designation);
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
long[] userGroupIds = null;

boolean sendEmail = true;

com.liferay.portal.service.ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), request);

UserLocalServiceUtil.addUser(creatorId,
themeDisplay.getCompanyId(), autoPassword, password1, password2,
autoScreenName, screenName, compemail, facebookId, openId,
LocaleUtil.getDefault(), firstName, middleName, lastName, prefixId,
suffixId, male, birthdayMonth, birthdayDay, birthdayYear, designation,
groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
serviceContext);

}
catch(Exception e){
e.printStackTrace();
}
}
i have tried many code posted in forum but nothing worked.......... please give me guide on this issue..
David H Nebinger
RE: creating new user via API
March 30, 2012 7:08 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8426

Join Date: September 1, 2006

Recent Posts

Do not post the same thing in multiple threads. I've posted a response here: http://www.liferay.com/community/forums/-/message_boards/message/13199278
RathnaDevi Chellaiah
RE: creating new user via API
April 2, 2012 2:51 AM
Answer

RathnaDevi Chellaiah

Rank: Junior Member

Posts: 29

Join Date: March 26, 2012

Recent Posts

hi Suresh,
can u share ur code.. am unable to create user inthe user_ table..
Rajesh Chaurasia
RE: creating new user via API
April 2, 2012 9:19 AM
Answer

Rajesh Chaurasia

Rank: Junior Member

Posts: 94

Join Date: August 18, 2011

Recent Posts

I have a scenarion similar to yours but with a difference .I create users when I am creating organisation .we have a use case where some default users be created with certain set of roles when we are trying to create organisation .
As you might be aware that certain entities like orgaisation , user ,etc have model listeners attached to them so that when we create a successful insert in one of these ,simultaneous entries go in associated model listeners.And this is the way liferay behaves.For your custom insert into a liferay db you may be able to insert a user in user_ table but you will not be able to use that user or at least refer to that user unless simulatneos insert sre being made in associated model listeners for user.

I am attaching a create user method that I used in my use case.Hope this answers your query to a certain extent:
private User insertOrgPublisher(ActionRequest actionRequest,Organization organization,ServiceContext serviceContext) throws PortalException, SystemException {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
long groupId= themeDisplay.getLayout().getGroupId();
String password1= "orgpub";//organization.getName().toLowerCase();
String domainName = null;
long facebookId=0;
String openId=null;
String firstName=organization.getName();
String lastName=organization.getName();
int prefixId=123;
int suffixId=234;
String jobTitle="Organization Publisher";
domainName = organization.getName();
domainName= domainName.trim();
if(domainName.contains(" ")) {
domainName = domainName.replaceAll("\\s+", "-");
}
String emailAddress="publisher@"+domainName+".com";
Role role = RoleLocalServiceUtil.getRole(companyId, "Organization Publisher");
User user = null;
if(role != null){
String greeting="Welcome "+role.getName();
long id = CounterLocalServiceUtil.increment(User.class.getName());
user = UserLocalServiceUtil.createUser(id);
user.setCompanyId(companyId);
user.setPassword(password1);
String screenName=organization.getName().toLowerCase()+id;
user.setScreenName(screenName);
user.setGreeting(greeting);
user.setEmailAddress(emailAddress);
user.setFacebookId(facebookId);
user.setOpenId(openId);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setJobTitle(jobTitle);
user.setCreateDate(new Date ());
user.setContactId(id+1);
user.setPasswordReset(true);
user.setPasswordModifiedDate(new Date());
user.setCreateDate(new Date());
user.setModifiedDate(new Date());
user.setLanguageId(themeDisplay.getLanguageId());
user.setTimeZoneId(themeDisplay.getTimeZone().getDisplayName());
UserLocalServiceUtil.addUser(user);

//Associate a role with user
long userid[] = {user.getUserId()};
//UserLocalServiceUtil.addRoleUsers(role.getRoleId(), userid);
long roleids[]={role.getRoleId()};
UserGroupRoleLocalServiceUtil.addUserGroupRoles(user.getUserId(), groupId, roleids);
ClassName clsNameUser = ClassNameLocalServiceUtil.getClassName("com.liferay.portal.model.User");
long classNameId=clsNameUser.getClassNameId();

//Insert Group for a user
long gpId = CounterLocalServiceUtil.increment(Group.class.getName());
Group userGrp = GroupLocalServiceUtil.createGroup(gpId);
userGrp.setClassNameId(classNameId);
userGrp.setClassPK(userid[0]);
userGrp.setCompanyId(companyId);
userGrp.setName("group"+String.valueOf(userid[0]));
userGrp.setFriendlyURL("/group"+gpId);
userGrp.setCreatorUserId(PortalUtil.getUserId(actionRequest));
userGrp.setActive(true);
GroupLocalServiceUtil.addGroup(userGrp);

//Insert Contact for a user
long idContact = user.getUserId() + 1;//CounterLocalServiceUtil.increment(Contact.class.getName());
Contact contact = ContactLocalServiceUtil.createContact(idContact);
contact.setCompanyId(companyId);
contact.setCreateDate(new Date());
contact.setUserName(screenName);
contact.setUserId(user.getUserId());
contact.setModifiedDate(new Date());
contact.setFirstName("contact-"+contact.getContactId());
contact.setLastName("contact-"+contact.getContactId());
contact.setMiddleName("contact-"+contact.getContactId());
contact.setPrefixId(prefixId);
contact.setBirthday(new Date());
contact.setSuffixId(suffixId);
contact.setJobTitle(jobTitle+contact.getContactId());
ContactLocalServiceUtil.addContact(contact);

//Create AssetEntry
long assetEntryId = user.getUserId()+5;//CounterLocalServiceUtil.increment(AssetEntry.class.getName());
AssetEntry ae = AssetEntryLocalServiceUtil.createAssetEntry(assetEntryId);
ae.setCompanyId(companyId);
ae.setClassPK(user.getUserId());
ae.setGroupId(userGrp.getGroupId());
ae.setClassNameId(classNameId);
AssetEntryLocalServiceUtil.addAssetEntry(ae);

//Insert ResourcePermission for a User
long resPermId = CounterLocalServiceUtil.increment(ResourcePermission.class.getName());
ResourcePermission rpEntry = ResourcePermissionLocalServiceUtil.createResourcePermission(resPermId);
rpEntry.setCompanyId(organization.getCompanyId());
rpEntry.setName("com.liferay.portal.model.User");
rpEntry.setRoleId(role.getRoleId());
rpEntry.setScope(4);
ResourcePermissionLocalServiceUtil.addResourcePermission(rpEntry);

//Insert Layoutset for public and private
long layoutSetIdPub = CounterLocalServiceUtil.increment(LayoutSet.class.getName());
LayoutSet layoutSetPub=LayoutSetLocalServiceUtil.createLayoutSet(layoutSetIdPub);
layoutSetPub.setCompanyId(companyId);
layoutSetPub.setPrivateLayout(false);
layoutSetPub.setGroupId(userGrp.getGroupId());
layoutSetPub.setThemeId("classic");
try{
LayoutSetLocalServiceUtil.addLayoutSet(layoutSetPub);
}catch(SystemException se){

}

long layoutSetIdPriv= CounterLocalServiceUtil.increment(LayoutSet.class.getName());
LayoutSet layoutSetPriv=LayoutSetLocalServiceUtil.createLayoutSet(layoutSetIdPriv);
layoutSetPriv.setCompanyId(companyId);
layoutSetPriv.setPrivateLayout(true);
layoutSetPriv.setThemeId("classic");
layoutSetPriv.setGroupId(userGrp.getGroupId());
try{
LayoutSetLocalServiceUtil.addLayoutSet(layoutSetPriv);
}catch(SystemException se){
}
}else{
return null;
}


return user;


}
Rajesh Chaurasia
RE: creating new user via API
April 2, 2012 9:24 AM
Answer

Rajesh Chaurasia

Rank: Junior Member

Posts: 94

Join Date: August 18, 2011

Recent Posts

In my recent post above , you should use CounterLocalServiceUtil to generate the id for an entity rather than evaluating it base don some other id as this might cause failure in inserts as there might be unique constraint violation .
piyush liferay
RE: creating new user via API
January 31, 2013 5:50 AM
Answer

piyush liferay

Rank: Junior Member

Posts: 40

Join Date: January 1, 2013

Recent Posts

Ahmed Hasan:
Yes, this is the right approach to create a new user using the local service api.

For the unique userId you have to get it as below.

long userId = CounterLocalServiceUtil.increment();

The rest of the code is fine.

For any help feel free to contact me,

Ahmed Hasan
CTO, TransIT mPower Labs (P) Ltd.
info@mpowerglobal.com
mPower Global Inc.
A Liferay expert company.


but after calling addUser() method gives some error :- Exception occurred inside getter of com.liferay.portal.model.impl.UserImpl.digest
Shankar Baba
RE: creating new user via API
March 28, 2013 4:28 AM
Answer

Shankar Baba

Rank: Regular Member

Posts: 144

Join Date: October 17, 2012

Recent Posts

Does any body have sample working example for this, if yes please attach the code with your reply.
Shankar Baba
RE: creating new user via API
March 30, 2013 4:13 AM
Answer

Shankar Baba

Rank: Regular Member

Posts: 144

Join Date: October 17, 2012

Recent Posts

man did u got solution for this problem?
leo Hudson
RE: creating new user via API
January 22, 2014 5:31 AM
Answer

leo Hudson

Rank: New Member

Posts: 1

Join Date: January 19, 2014

Recent Posts

Suresh Chinna Pillai:
Hi friend,
Thank you for your quick reply. I found the solution for this issue. I use "UserLocalServiceUtil.addUser(long creatorUserId, long companyId, boolean autoPassword,
String password1, String password2, boolean autoScreenName,
String screenName, String emailAddress, long facebookId, String openId,
Locale locale, String firstName, String middleName, String lastName,
int prefixId, int suffixId, boolean male, int birthdayMonth,
int birthdayDay, int birthdayYear, String jobTitle, long[] groupIds,
long[] organizationIds, long[] roleIds, long[] userGroupIds,
boolean sendEmail, ServiceContext serviceContext)"
method.

It works fine.

Can you have any idea about how to add the user to a group..?

Thanks in advance..

-Suresh.


Hi Suresh
can you explain how did you were able to create users in Liferay Portal
did you used SOAP/JSON or java invocation ??

how did you made a connection ???
saritha reddy
RE: creating new user via API
June 30, 2014 4:54 AM
Answer

saritha reddy

Rank: Junior Member

Posts: 95

Join Date: January 27, 2014

Recent Posts

Hi Rajesh

First of all thank you for that code snippet.

Sorry to pick old call but when am trying to implement the the your above mentioned code
am getting error like NoSuchMethodException with the following method.

private User insertOrgPublisher(ActionRequest actionRequest,Organization organization,ServiceContext serviceContext) throws PortalException, SystemException {

}

Could you please help me with this error


Thank you


Regards
Saritha
David H Nebinger
RE: creating new user via API
June 30, 2014 5:28 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8426

Join Date: September 1, 2006

Recent Posts

saritha reddy:
Sorry to pick old call but when am trying to implement the the your above mentioned code
am getting error like NoSuchMethodException with the following method.

private User insertOrgPublisher(ActionRequest actionRequest,Organization organization,ServiceContext serviceContext) throws PortalException, SystemException;


Well that's the thing with picking up dead code to use w/o understanding. This thread is over a year old and most likely talking about a previous version of Liferay than what you're using.

You should be able to adapt the concepts into your code for the version you're using, it will just take a little effort on your part.