Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Valerio Stark
Custom Registration Portlet
January 23, 2013 3:22 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

Hello! I have to do an exercise for university. I have to create a registration portlet. I have done a form with Name, LastName, Username, Password and Email Address.
I want that when I have insert all personal informations, new user was written in database. So I do this:

 1public void login(ActionRequest req, ActionResponse res) throws IOException, ReadOnlyException, ValidatorException, SystemException, com.liferay.portal.kernel.exception.PortalException{
 2        PortletPreferences p=req.getPreferences();
 3        String n= req.getParameter("nome");
 4        String c= req.getParameter("cognome");
 5        String u= req.getParameter("user");
 6        String e= req.getParameter("email");
 7        String psw= req.getParameter("password");
 8        String rpsw= req.getParameter("ripeti");
 9        if(n.equals("")){
10            SessionErrors.add(req,"bad1");
11        }
12        else if(c.equals("")){
13            SessionErrors.add(req,"bad2");
14        }
15        else if(u.equals("")){
16            SessionErrors.add(req,"bad3");   
17        }
18        else if(e.equals("")){
19            SessionErrors.add(req,"bad4");
20        }
21        else if(psw.equals("")){
22            SessionErrors.add(req,"bad5");
23        }
24        else if(rpsw.equals("")){
25            SessionErrors.add(req,"bad6");
26        }
27        else if(!psw.equals(rpsw)){
28            SessionErrors.add(req,"nopass");
29        }
30        else{
31            long id=CounterLocalServiceUtil.increment();
32            User utente=UserLocalServiceUtil.createUser(id);
33            utente.setFirstName(n);
34            utente.setLastName(c);
35            utente.setScreenName(u);
36            utente.setPassword(psw);
37            utente.setEmailAddress(e);
38            try {
39                UserLocalServiceUtil.addUser(utente);
40            }
41            catch (SystemException e2) {
42                e2.printStackTrace();
43            }
44            p.setValue("user",u);
45            p.store();
46            SessionMessages.add(req,"ok");
47            res.setRenderParameter("jspPage","/html/prova/edit.jsp");
48        }
49    }


But also if I see message ok, I won't have new user in database.
What I have to do?

This istruction not work: UserLocalServiceUtil.addUser(utente);
Jan Geißler
RE: Custom Registration Portlet
January 23, 2013 3:23 AM
Answer

Jan Geißler

Rank: Expert

Posts: 356

Join Date: July 5, 2011

Recent Posts

Try addUser(many many parameters)
Valerio Stark
RE: Custom Registration Portlet
January 23, 2013 3:52 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

I have tried with this:

 1ThemeDisplay theme= (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
 2            long creatorUserId = theme.getUserId(); // default liferay user
 3            long companyId = theme.getCompanyId(); // default company
 4            boolean autoPassword = false;
 5            String password2 = "";
 6            boolean autoScreenName = false;
 7            long facebookId = 0;
 8            String openId = "";
 9            Locale locale = theme.getLocale();
10            String middleName = "";
11            int prefixId = 0;
12            int suffixId = 0;
13            boolean male = true;   
14            int birthdayMonth = 10;
15            int birthdayDay = 10;
16            int birthdayYear = 2010;
17            String jobTitle = "";
18            long[] groupIds = null;
19            long[] organizationIds = null;
20            long[] roleIds = null;
21            long[] userGroupIds = null;
22            boolean sendEmail = false;


And I have use addUser with all parametres.
But I have seen: "Your request failed to complete". Without other informations
Siby Mathew
RE: Custom Registration Portlet
January 23, 2013 6:20 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

Hi Valerio,
In your code I couldn't find 'password1;. Hope you had given both password1 and password2 as params for addUser.


Thanks,
SIby
Valerio Stark
RE: Custom Registration Portlet
January 23, 2013 6:50 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

I have use psw and not password1 because with

1String psw= req.getParameter("password");


I catch value from the form
Valerio Stark
RE: Custom Registration Portlet
January 23, 2013 7:47 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

Obiouvsly I have done also this:

1try {
2                UserLocalServiceUtil.addUser(creatorUserId,companyId,autoPassword, psw,password2,autoScreenName,u,e,facebookId,openId,locale,n,middleName,c,prefixId,suffixId,male,birthdayMonth,birthdayDay,birthdayYear,jobTitle,groupIds,organizationIds,roleIds,userGroupIds,sendEmail,ServiceContextFactory.getInstance(req));
3            }
4            catch (SystemException e2) {
5                e2.printStackTrace();
6            }
Matt S.
RE: Custom Registration Portlet
January 23, 2013 8:02 AM
Answer

Matt S.

Rank: Junior Member

Posts: 36

Join Date: November 29, 2012

Recent Posts

Hi all,

I have a problem similar to Valerio and I have a question...how can I see if an user is added into database of Liferay? Because I use the same code of Valerio but the user doesn't appear into user table in the control panel.
Valerio Stark
RE: Custom Registration Portlet
January 24, 2013 1:38 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

Please, can help me?
Siby Mathew
RE: Custom Registration Portlet
January 24, 2013 2:56 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

Hi Valerio,
Both the psw and password2 should be of same value .
This is because they are used in password confirmation.
See this :
http://www.liferay.com/community/forums/-/message_boards/message/18015925

- Please make sure both passwords are same.
- Also please check if you are giving a valid screenName.

Thanks,
Siby
Matt S.
RE: Custom Registration Portlet
January 24, 2013 7:44 AM
Answer

Matt S.

Rank: Junior Member

Posts: 36

Join Date: November 29, 2012

Recent Posts

Regarding the user table, is there a way to see if a user is in the database of liferay? And a way to make him appear in the user table in control panel-->user and organization? Because i use the same code but user don't appear in the table
Valerio Stark
RE: Custom Registration Portlet
January 25, 2013 2:01 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

I have insert same psw but the answer is the same: Your request failed to complete

What I have to do?
Siby Mathew
RE: Custom Registration Portlet
January 25, 2013 2:26 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

Hi Valerio/Matt
Hope you checked the screenName doesnt exist already in the DB.
The best way is to put breakpoints in your code and debug..

Thanks,
Siby
Valerio Stark
RE: Custom Registration Portlet
January 25, 2013 3:31 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

I think that I needn't to a debug because this is my code:

 1ThemeDisplay theme= (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
 2            long creatorUserId = theme.getUserId(); // default liferay user
 3            long companyId = theme.getCompanyId(); // default company
 4            boolean autoPassword = true;
 5            boolean autoScreenName = true;
 6            long facebookId = 0;
 7            String openId = "";
 8            Locale locale = theme.getLocale();
 9            String middleName = "";
10            int prefixId = 0;
11            int suffixId = 0;
12            boolean male = true;   
13            int birthdayMonth = 10;
14            int birthdayDay = 10;
15            int birthdayYear = 2010;
16            String jobTitle = "";
17            long[] groupIds = null;
18            long[] organizationIds = null;
19            long[] roleIds = null;
20            long[] userGroupIds = null;
21            boolean sendEmail = false;
22            UserLocalServiceUtil.addUser(creatorUserId,companyId,autoPassword, psw,psw,autoScreenName,u,e,facebookId,openId,locale,n,middleName,c,prefixId,suffixId,male,birthdayMonth,birthdayDay,birthdayYear,jobTitle,groupIds,organizationIds,roleIds,userGroupIds,sendEmail,ServiceContextFactory.getInstance(req));


If I delete this:

1UserLocalServiceUtil.addUser(creatorUserId,companyId,autoPassword, psw,psw,autoScreenName,u,e,facebookId,openId,locale,n,middleName,c,prefixId,suffixId,male,birthdayMonth,birthdayDay,birthdayYear,jobTitle,groupIds,organizationIds,roleIds,userGroupIds,sendEmail,ServiceContextFactory.getInstance(req));


portlet work correctly but obiouvsly don't add user in database.

So I have tried to do this:

 1
 2long id=CounterLocalServiceUtil.increment();
 3            User utente=UserLocalServiceUtil.createUser(id);
 4            utente.setFirstName(n);
 5            utente.setLastName(c);
 6            utente.setScreenName(u);
 7            utente.setPassword(psw);
 8            utente.setEmailAddress(e);
 9            UserLocalServiceUtil.addUser(utente);


portlet work correctly but don't add user in database. Work the same that code before but in this case it would be add a new user but it don't made this

So I tried with try/cath:

 1
 2long id=CounterLocalServiceUtil.increment();
 3            User utente=UserLocalServiceUtil.createUser(id);
 4            utente.setFirstName(n);
 5            utente.setLastName(c);
 6            utente.setScreenName(u);
 7            utente.setPassword(psw);
 8            utente.setEmailAddress(e);
 9try {
10                UserLocalServiceUtil.addUser(utente);
11            }
12            catch (SystemException e2) {
13                e2.printStackTrace();
14            }


The same!

What I have to do? Why user don't is added in database?
Siby Mathew
RE: Custom Registration Portlet
January 25, 2013 3:18 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

Hi Valerio,
Just wanted to know if you are giving valid values as parameter..as it can fail inside the UserLocalServiceImpl validation.
Debugging is your best bet.

Thanks,
Siby
Valerio Stark
RE: Custom Registration Portlet
January 25, 2013 3:33 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

Ok now I try.
Before I have tried another thing:

1System.out.println(UserLocalServiceUtil.getUserById(id));


After try/cath

Because I wanted to see if db was written and is only a visual problem. But if I have this row of code portlet said me: "Your request failed to complete"

So I think that there are some problem with UserLocalServiceUtil
Matt S.
RE: Custom Registration Portlet
January 25, 2013 3:57 AM
Answer

Matt S.

Rank: Junior Member

Posts: 36

Join Date: November 29, 2012

Recent Posts

I possible do a query to user_ table of liferay to control if an user is added to database? How can do this?
Valerio Stark
RE: Custom Registration Portlet
January 28, 2013 1:04 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

Up. Please I have very much problems emoticon
Siby Mathew
RE: Custom Registration Portlet
January 28, 2013 5:35 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

Hi Valerio,
You said after try-catch you put getUserById() method call... but the code might have failed before itself...
Did you try debugging as I had asked you ?

Thanks,
Siby
Valerio Stark
RE: Custom Registration Portlet
January 28, 2013 7:54 AM
Answer

Valerio Stark

Rank: New Member

Posts: 13

Join Date: January 7, 2013

Recent Posts

I have difficult to do debugging. I have put as breakpoint code after try. But I don't know how help you to understand