Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Anonymous
How to add a new user in my web application
November 10, 2007 12:39 PM
Answer

Anonymous

I want to add a new user in my own web application. That is, login in my index.jsp,and use a button to call liferay, and the user will login in liferay automatically with the user information from my application. So i need to create a new user in liferay with the same username and password.
I try to use the method "com.liferay.portal.service.UserServiceUtil.addUser(...)" in my program, but it didn't work.
Can someon help me and give me some tips?

p.s. My web application is placed in "webapps" folder of the liferay-tomcat4.3.3.
Roman Hoyenko
RE: How to add a new user in my web application
November 12, 2007 7:22 AM
Answer

Roman Hoyenko

Community Moderator

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

The method you used should work. Did you get any exception? What version of Liferay are you using?
Leon Dai
RE: How to add a new user in my web application
November 12, 2007 8:12 AM
Answer

Leon Dai

Rank: New Member

Posts: 18

Join Date: June 28, 2007

Recent Posts

Hi,
I don't get "exception". But I can't find this new user in my database(mysql). I use the version tomcat-liferay 4.3.3
My code is as follows:

 1[size=6][font=Courier New]
 2......
 3Long companyId = new Long("1");
 4boolean autoPassword = false;
 5String pwd ="test";
 6String password1 = pwd;
 7String password2 = pwd;
 8boolean autoScreenName = true;
 9String screenName = "";
10String emailAddress=null;
11String firstName=null;
12String lastName=null;
13try {
14       emailAddress="testUser3@test.com";
15       firstName = "ufirst";
16       lastName = "ulast";
17       Locale locale = Locale.US;
18       String middleName = "";
19       int prefixId=0;
20       int suffixId=0;
21       boolean male = true;
22       int birthdayMonth = 1;
23       int birthdayDay = 1;
24       int birthdayYear = 2000;
25       String jobTitle = "";
26       Long organizationId = new Long("0");
27       long locationId = new Long("0");
28       boolean sendEmail = false;
29       User user = null;
30       user = UserServiceUtil.addUser(companyId, autoPassword, password1, password2,
31        autoScreenName, screenName, emailAddress,
32        locale, firstName, middleName, lastName,
33        prefixId, suffixId, male, birthdayMonth, birthdayDay,
34        birthdayYear, jobTitle, organizationId, locationId, sendEmail);
35        }
36catch (PortalException e1) {
37    e1.printStackTrace();
38        }
39catch (SystemException e1) {
40    e1.printStackTrace();
41        }
42catch (RemoteException e1) {
43    e1.printStackTrace();
44        }[/font][/size]
Roman Hoyenko
RE: How to add a new user in my web application
November 12, 2007 7:51 AM
Answer

Roman Hoyenko

Community Moderator

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

Here is my code:

boolean male = true;
String password="testtest", companyId="liferay.com", jobTitle = "", organizationId = "", locationId = "";
String password1=password, password2=password;
String nickName="", prefixId = "", suffixId = "";
Calendar birthday = Calendar.getInstance();
boolean autoUserId = false;
boolean autoPassword = false;
boolean passwordReset = false;


UserLocalServiceUtil.addUser("liferay.com.1",companyId, autoUserId, userId, autoPassword, password1, password2, passwordReset, user.getEmail(), Locale.US,user.getFirstName(), "", user.getLastName(), nickName, prefixId, suffixId, male, birthday.get(Calendar.MONTH), birthday.get(Calendar.DATE), birthday.get(Calendar.YEAR), jobTitle, organizationId, locationId);


It took me some time to debug it - liferay doesn't like some of the emails, companyId should be registered in Liferay db, etc.

This code worked for 4.1 it might be that something changed in later versions.
Leon Dai
RE: How to add a new user in my web application
November 12, 2007 8:11 AM
Answer

Leon Dai

Rank: New Member

Posts: 18

Join Date: June 28, 2007

Recent Posts

By the way, if it works(that is,the user is added into the database successfully), then how can i get into the new user's public/private pages in my program (for example: response.sendRedirect("..."), which URL is right)?
Roman Hoyenko
RE: How to add a new user in my web application
November 12, 2007 9:17 AM
Answer

Roman Hoyenko

Community Moderator

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

look at login.jsp to see how it is done.
Leon Dai
RE: How to add a new user in my web application
November 13, 2007 3:38 AM
Answer

Leon Dai

Rank: New Member

Posts: 18

Join Date: June 28, 2007

Recent Posts

Hi,
I have looked at login.jsp and LoginAction.java, but I still don't know how to redirect from my own application:
I try the code:

1[size=5]ses.setAttribute("username","testUser3@test.com");
2ses.setAttribute("password","test");
3response.sendRedirect("/c/portal/login?redirect=/user/testuser3/1");
4[/size]


After "redirect", i still need to input password.
I don't know, is it right or? How can I login the liferay from my application without input of username and password once more? Can you give some tip?
Thanks a lot.
Roman Hoyenko
RE: How to add a new user in my web application
November 13, 2007 7:42 AM
Answer

Roman Hoyenko

Community Moderator

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

You can debug and see why it is failing.

Set up breakpoint in portal-impl\src\com\liferay\portal\action\LoginAction.java and see what is going on.
Arvind Patil
RE: How to add a new user in my web application
November 15, 2011 8:54 PM
Answer

Arvind Patil

Rank: New Member

Posts: 10

Join Date: October 26, 2011

Recent Posts

Thanks in advance.
I am trying to access following method from portlet .I tried UserServiceUtil.updateUser.It inserted user in database tables in User_ but when I try to see view all users in Liferay Control Panel I could not see added users.They are just in USer_
I am trying with UserLocalServiceUtil.addUser() but it is giving me errors.



long creatorUserId=23455;
long companyId=54444;
boolean autoPassword=false;
String password1="Arvind";
String password2="Patil";
boolean autoScreenName=false;
String screenName="Arvind.Patil";
String emailAddress="abc@yahoo.com";
long facebookId=12334455;
String openId="Rohan";
Locale locale=Locale.US;
String firstName="Arvind";
String middleName="S";
String lastName="Patil";
int prefixId=123;
int suffixId=234;
boolean male=false;
int birthdayMonth=11;
int birthdayDay=12;
int birthdayYear=61;
String jobTitle="Student";
long[] groupIds={0};
long[] organizationIds={0};
long[] roleIds={0};
long[] userGroupIds={0};
boolean sendEmail=false;
ServiceContext serviceContext = new ServiceContext();


UserLocalServiceUtil.addUser(creatorUserId,
companyId,
autoPassword,
password1,
password2,
autoScreenName,
screenName,
emailAddress,
facebookId,
openId,
locale,
firstName,
middleName,
lastName,
prefixId,
suffixId,
male,
birthdayMonth,
birthdayDay,
birthdayYear,
jobTitle,
groupIds,
organizationIds,
roleIds,
userGroupIds,
sendEmail,serviceContext
);

at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
at com.liferay.portal.servlet.filters.threadlocal.ThreadLocalFilter.processFilter(ThreadLocalFilter.java:35)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.servlet.ServletException: com.liferay.portal.NoSuchCompanyException: No Company exists with the primary key 54444
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
at com.liferay.portal.kernel.servlet.PageContextWrapper.handlePageException(PageContextWrapper.java:141)
at org.apache.jsp.view_jsp._jspService(view_jsp.java:268)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
... 222 more
Caused by: com.liferay.portal.NoSuchCompanyException: No Company exists with the primary key 54444
at com.liferay.portal.service.persistence.CompanyPersistenceImpl.findByPrimaryKey(CompanyPersistenceImpl.java:436)
Arvind Patil
RE: How to add a new user in my web application
November 15, 2011 9:11 PM
Answer

Arvind Patil

Rank: New Member

Posts: 10

Join Date: October 26, 2011

Recent Posts

I am using liferay 6.0.3

Thanks in advance.
I am trying to access following method from portlet .I tried UserServiceUtil.updateUser.It inserted user in database tables in User_ but when I try to see view all users in Liferay Control Panel I could not see added users.They are just in USer_
I am trying with UserLocalServiceUtil.addUser() but it is giving me errors.Could you please help me?



long creatorUserId=23455;
long companyId=54444;
boolean autoPassword=false;
String password1="Arvind";
String password2="Patil";
boolean autoScreenName=false;
String screenName="Arvind.Patil";
String emailAddress="abc@yahoo.com";
long facebookId=12334455;
String openId="Rohan";
Locale locale=Locale.US;
String firstName="Arvind";
String middleName="S";
String lastName="Patil";
int prefixId=123;
int suffixId=234;
boolean male=false;
int birthdayMonth=11;
int birthdayDay=12;
int birthdayYear=61;
String jobTitle="Student";
long[] groupIds={0};
long[] organizationIds={0};
long[] roleIds={0};
long[] userGroupIds={0};
boolean sendEmail=false;
ServiceContext serviceContext = new ServiceContext();


UserLocalServiceUtil.addUser(creatorUserId,
companyId,
autoPassword,
password1,
password2,
autoScreenName,
screenName,
emailAddress,
facebookId,
openId,
locale,
firstName,
middleName,
lastName,
prefixId,
suffixId,
male,
birthdayMonth,
birthdayDay,
birthdayYear,
jobTitle,
groupIds,
organizationIds,
roleIds,
userGroupIds,
sendEmail,serviceContext
);

at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
at com.liferay.portal.servlet.filters.threadlocal.ThreadLocalFilter.processFilter(ThreadLocalFilter.java:35)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.servlet.ServletException: com.liferay.portal.NoSuchCompanyException: No Company exists with the primary key 54444
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
at com.liferay.portal.kernel.servlet.PageContextWrapper.handlePageException(PageContextWrapper.java:141)
at org.apache.jsp.view_jsp._jspService(view_jsp.java:268)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
... 222 more
Caused by: com.liferay.portal.NoSuchCompanyException: No Company exists with the primary key 54444