论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
creating new user via API Marian Rosko 2009年4月3日 上午5:50
RE: creating new user via API Luc Pons 2009年5月20日 上午12:51
RE: creating new user via API Ahmed Hasan 2009年5月20日 上午4:22
RE: creating new user via API Ayaz Pasha 2009年5月20日 上午5:11
RE: creating new user via API Ayaz Pasha 2009年5月20日 上午5:35
RE: creating new user via API Juan M. Gomez 2009年6月24日 上午10:42
RE: creating new user via API Amos Fong 2009年6月24日 上午10:46
RE: creating new user via API Juan M. Gomez 2009年6月24日 下午3:04
RE: creating new user via API Amos Fong 2009年9月10日 下午3:43
RE: creating new user via API 匿名 2009年11月23日 上午7:06
RE: creating new user via API Man V K 2009年12月9日 上午12:49
RE: creating new user via API Shankar Baba 2013年3月30日 上午4:13
RE: creating new user via API li guicheng 2010年8月9日 下午6:10
RE: creating new user via API Suresh Chinna Pillai 2011年2月14日 上午12:55
RE: creating new user via API Siddhartha Bera 2011年2月15日 上午11:21
RE: creating new user via API Suresh Chinna Pillai 2011年2月16日 上午7:45
RE: creating new user via API RathnaDevi Chellaiah 2012年4月2日 上午2:51
RE: creating new user via API leo Hudson 2014年1月22日 上午5:31
RE: creating new user via API RathnaDevi Chellaiah 2012年3月30日 上午6:50
RE: creating new user via API David H Nebinger 2012年3月30日 上午7:08
RE: creating new user via API piyush liferay 2013年1月31日 上午5:50
RE: creating new user via API Shankar Baba 2013年3月28日 上午4:28
RE: creating new user via API Pepe Laberta 2010年11月5日 上午8:04
RE: creating new user via API Rajesh Chaurasia 2012年4月2日 上午9:19
RE: creating new user via API Rajesh Chaurasia 2012年4月2日 上午9:24
RE: creating new user via API saritha reddy 2014年6月30日 上午4:54
RE: creating new user via API David H Nebinger 2014年6月30日 上午5:28
Marian Rosko
creating new user via API
2009年4月3日 上午5:50
答复

Marian Rosko

等级: New Member

帖子: 1

加入日期: 2009年4月3日

最近的帖子

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
2009年5月20日 上午12:51
答复

Luc Pons

等级: Junior Member

帖子: 70

加入日期: 2008年12月3日

最近的帖子

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
2009年5月20日 上午4:22
答复

Ahmed Hasan

等级: Expert

帖子: 303

加入日期: 2007年4月13日

最近的帖子

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
2009年5月20日 上午5:11
答复

Ayaz Pasha

等级: Junior Member

帖子: 78

加入日期: 2008年8月1日

最近的帖子

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
2009年5月20日 上午5:35
答复

Ayaz Pasha

等级: Junior Member

帖子: 78

加入日期: 2008年8月1日

最近的帖子

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
2009年6月24日 上午10:42
答复

Juan M. Gomez

等级: Junior Member

帖子: 69

加入日期: 2007年11月7日

最近的帖子

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
2009年6月24日 上午10:46
答复

Amos Fong

LIFERAY STAFF

等级: Liferay Legend

帖子: 1844

加入日期: 2008年10月7日

最近的帖子

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
2009年6月24日 下午3:04
答复

Juan M. Gomez

等级: Junior Member

帖子: 69

加入日期: 2007年11月7日

最近的帖子

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
2009年9月10日 下午3:43
答复

Amos Fong

LIFERAY STAFF

等级: Liferay Legend

帖子: 1844

加入日期: 2008年10月7日

最近的帖子

Juan,

Sorry for late response, organizations are not indexed so no.
匿名
RE: creating new user via API
2009年11月23日 上午7:06
答复

匿名

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
2009年12月9日 上午12:49
答复

Man V K

等级: Regular Member

帖子: 139

加入日期: 2007年12月4日

最近的帖子

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
2010年8月9日 下午6:10
答复

li guicheng

等级: Junior Member

帖子: 25

加入日期: 2010年3月28日

最近的帖子

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
2010年11月5日 上午8:04
答复

Pepe Laberta

等级: New Member

帖子: 7

加入日期: 2010年5月12日

最近的帖子

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
2011年2月14日 上午12:55
答复

Suresh Chinna Pillai

等级: New Member

帖子: 16

加入日期: 2011年2月13日

最近的帖子

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
2011年2月15日 上午11:21
答复

Siddhartha Bera

等级: New Member

帖子: 2

加入日期: 2011年2月4日

最近的帖子

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
2011年2月16日 上午7:45
答复

Suresh Chinna Pillai

等级: New Member

帖子: 16

加入日期: 2011年2月13日

最近的帖子

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
2012年3月30日 上午6:50
答复

RathnaDevi Chellaiah

等级: Junior Member

帖子: 29

加入日期: 2012年3月26日

最近的帖子

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
2012年3月30日 上午7:08
答复

David H Nebinger

等级: Liferay Legend

帖子: 6134

加入日期: 2006年9月1日

最近的帖子

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
2012年4月2日 上午2:51
答复

RathnaDevi Chellaiah

等级: Junior Member

帖子: 29

加入日期: 2012年3月26日

最近的帖子

hi Suresh,
can u share ur code.. am unable to create user inthe user_ table..
Rajesh Chaurasia
RE: creating new user via API
2012年4月2日 上午9:19
答复

Rajesh Chaurasia

等级: Junior Member

帖子: 86

加入日期: 2011年8月18日

最近的帖子

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
2012年4月2日 上午9:24
答复

Rajesh Chaurasia

等级: Junior Member

帖子: 86

加入日期: 2011年8月18日

最近的帖子

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
2013年1月31日 上午5:50
答复

piyush liferay

等级: Junior Member

帖子: 40

加入日期: 2013年1月1日

最近的帖子

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
2013年3月28日 上午4:28
答复

Shankar Baba

等级: Regular Member

帖子: 144

加入日期: 2012年10月17日

最近的帖子

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
2013年3月30日 上午4:13
答复

Shankar Baba

等级: Regular Member

帖子: 144

加入日期: 2012年10月17日

最近的帖子

man did u got solution for this problem?
leo Hudson
RE: creating new user via API
2014年1月22日 上午5:31
答复

leo Hudson

等级: New Member

帖子: 1

加入日期: 2014年1月19日

最近的帖子

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
2014年6月30日 上午4:54
答复

saritha reddy

等级: Junior Member

帖子: 48

加入日期: 2014年1月27日

最近的帖子

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
2014年6月30日 上午5:28
答复

David H Nebinger

等级: Liferay Legend

帖子: 6134

加入日期: 2006年9月1日

最近的帖子

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.