Forums de discussion

how to add user using UserlocalServiceUtil in Liferay ?

Ck soni, modifié il y a 10 années.

how to add user using UserlocalServiceUtil in Liferay ?

New Member Publications: 19 Date d'inscription: 28/02/14 Publications récentes
Hello frnds how can i add user in liferay _user table using eclips ide ?
i m new to liferay so pls give appropriate and easy answer.
I want sample code contains .set methods ...bcoz i want to add some limited and my selected fields .

here is my code:



<%@page import="com.mysql.jdbc.Util"%>
<%@page import="java.io.*,java.util.*,java.text.*,com.liferay.counter.service.CounterLocalServiceUtil"%>
<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ page import="com.liferay.portal.model.*,com.liferay.portal.service.ServiceContext,com.liferay.portal.service.persistence.*,com.mysql.jdbc.log.Log" %>

<portlet:defineObjects />

<%

try
{
long userId = CounterLocalServiceUtil.increment();
User user = UserUtil.create(userId);

user.setContactId(userId+1);
user.setUserId(userId);
user.setCompanyId(10201);
user.setCreateDate(new Date());
user.setModifiedDate(new Date());
user.setDefaultUser(false);
user.setPassword("abcd");
user.setPasswordEncrypted(true);
user.setPasswordReset(false);
user.setPasswordModified(true);
user.setDigest("dsds");
user.setReminderQueryQuestion("dsds");
user.setReminderQueryAnswer("dsds");
user.setGraceLoginCount(1);
user.setScreenName("user");
user.setEmailAddress("ck@ymail.com");
user.setFacebookId(1);
user.setLdapServerId(0);
user.setOpenId("hi ist open");
user.setPortraitId(0);
user.setLanguageId("US");
user.setTimeZoneId("UTS");
user.setGreeting("Welcome User");
user.setComments("kal");
user.setFirstName("My");
user.setMiddleName("soni");
user.setLastName("sasas");
user.setJobTitle("dsds");
user.setLoginDate(new Date());
user.setLoginIP("127.0.0.1");
user.setLastLoginDate(new Date());
user.setLastLoginIP("ffff");
user.setFailedLoginAttempts(3);
user.setLockout(false);
user.setLockoutDate(new Date());
user.setAgreedToTermsOfUse(true);
user.setEmailAddressVerified(false);
user.setStatus(1);
UserLocalServiceUtil.addUser(user);
}
catch (Exception e)
{
e.printStackTrace();
}
%>

and It show error like :

indexing , could not execute jdbc batch etc...
thumbnail
mohammad azaruddin, modifié il y a 10 années.

RE: how to add user using UserlocalServiceUtil in Liferay ?

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
Use this method

User user = UserServiceUtil.addUserWithWorkflow(company.getCompanyId(),
autoPassword, password1, password2, autoScreenName, screenName,
emailAddress, facebookId, openId, themeDisplay.getLocale(),
firstName, middleName, lastName, prefixId, suffixId, male,
birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
organizationIds, roleIds, userGroupIds, sendEmail,
serviceContext);
thumbnail
Hitesh Trivedi, modifié il y a 10 années.

RE: how to add user using UserlocalServiceUtil in Liferay ?

New Member Publications: 17 Date d'inscription: 24/01/14 Publications récentes
Mohammad ...
ck need reply as below..


user.setContactId(userId+1);
user.setUserId(userId);
user.setCompanyId(10201);
user.setCreateDate(new Date());
user.setModifiedDate(new Date());.
..
.
.
.
.
suggest me i also want answer ....
thumbnail
Ankit c p, modifié il y a 10 années.

RE: how to add user using UserlocalServiceUtil in Liferay ?

Junior Member Publications: 78 Date d'inscription: 07/01/10 Publications récentes
Update with your desired values in below addUser method

long[] userGroupIds = {};
long[] roleIds = {ParamUtil.getLong(actionRequest, "roleId")};
long[] organizationIds = new long[] { ParamUtil.getLong(actionRequest,
"organizationId") };
long[] groupIds = {};

ServiceContext serviceContext = ServiceContextFactory.getInstance(
User.class.getName(), actionRequest);

User user = UserLocalServiceUtil.addUser(0, companyId, false, password1,
password2, false, screenName, emailAddress, 0,
StringPool.BLANK, LocaleUtil.getDefault(), firstName,
middleName, lastName, 0, 0, true, Calendar.JANUARY, 1, 1979,
StringPool.BLANK, groupIds, organizationIds, roleIds,
userGroupIds, false, serviceContext);
Ck soni, modifié il y a 10 années.

RE: how to add user using UserlocalServiceUtil in Liferay ?

New Member Publications: 19 Date d'inscription: 28/02/14 Publications récentes
using this method it successfully add user but not in user table it add another table.but i want to add user in liferay ( _user ) table.
so what to do ?
thumbnail
mohammad azaruddin, modifié il y a 10 années.

RE: how to add user using UserlocalServiceUtil in Liferay ?

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
Did u try addUserWithWorkflow method....?
thumbnail
Akash Jaisawal, modifié il y a 8 années.

RE: how to add user using UserlocalServiceUtil in Liferay ?

Regular Member Publications: 141 Date d'inscription: 03/03/12 Publications récentes
mohammad azaruddin:
Did u try addUserWithWorkflow method....?



Hello mohammad,

can you please tell me where i am doing wrong?

	ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
		long companyId = themeDisplay.getCompanyId();
		long groupId= themeDisplay.getLayout().getGroupId();
		String domainName = null;
		long facebookId=0;
		String openId=null;
		int prefixId=123;
		int suffixId=234;
		User user = null;
		String jobTitle="Organization Publisher";
		domainName = organization.getName();
		domainName= domainName.trim();



/*UserLocalServiceUtil.addUser(user);*/		
				    try{
				         user = UserLocalServiceUtil.addUser(user);
				       }
				    catch(UndeclaredThrowableException ex){
				    	_log.info("----"+ex);
				    	_log.info("----"+ex.getCause());
				    }
				    _log.info("Exit From UserLocalService Util-----"+user);


unable to create user.