Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Valerio Stark
Custom Registration Portlet
23. Januar 2013 03:22
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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
23. Januar 2013 03:23
Antwort

Jan Geißler

Rang: Expert

Nachrichten: 356

Eintrittsdatum: 5. Juli 2011

Neue Beiträge

Try addUser(many many parameters)
Valerio Stark
RE: Custom Registration Portlet
23. Januar 2013 03:52
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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
23. Januar 2013 06:20
Antwort

Siby Mathew

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 4. März 2011

Neue Beiträge

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
23. Januar 2013 06:50
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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
23. Januar 2013 07:47
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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
23. Januar 2013 08:02
Antwort

Matt S.

Rang: Junior Member

Nachrichten: 36

Eintrittsdatum: 29. November 2012

Neue Beiträge

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
24. Januar 2013 01:38
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

Please, can help me?
Siby Mathew
RE: Custom Registration Portlet
24. Januar 2013 02:56
Antwort

Siby Mathew

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 4. März 2011

Neue Beiträge

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
24. Januar 2013 07:44
Antwort

Matt S.

Rang: Junior Member

Nachrichten: 36

Eintrittsdatum: 29. November 2012

Neue Beiträge

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
25. Januar 2013 02:01
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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
25. Januar 2013 02:26
Antwort

Siby Mathew

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 4. März 2011

Neue Beiträge

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
25. Januar 2013 03:31
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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
25. Januar 2013 03:18
Antwort

Siby Mathew

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 4. März 2011

Neue Beiträge

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
25. Januar 2013 03:33
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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
25. Januar 2013 03:57
Antwort

Matt S.

Rang: Junior Member

Nachrichten: 36

Eintrittsdatum: 29. November 2012

Neue Beiträge

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
28. Januar 2013 01:04
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

Up. Please I have very much problems emoticon
Siby Mathew
RE: Custom Registration Portlet
28. Januar 2013 05:35
Antwort

Siby Mathew

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 4. März 2011

Neue Beiträge

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
28. Januar 2013 07:54
Antwort

Valerio Stark

Rang: New Member

Nachrichten: 13

Eintrittsdatum: 7. Januar 2013

Neue Beiträge

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