Fórumok

Custom Registration Portlet

Valerio Stark, módosítva 11 év-val korábban

Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
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:

public void login(ActionRequest req, ActionResponse res) throws IOException, ReadOnlyException, ValidatorException, SystemException, com.liferay.portal.kernel.exception.PortalException{
		PortletPreferences p=req.getPreferences();
		String n= req.getParameter("nome");
		String c= req.getParameter("cognome");
		String u= req.getParameter("user");
		String e= req.getParameter("email");
		String psw= req.getParameter("password");
		String rpsw= req.getParameter("ripeti");
		if(n.equals("")){
			SessionErrors.add(req,"bad1");
		}
		else if(c.equals("")){
			SessionErrors.add(req,"bad2");
		}
		else if(u.equals("")){
			SessionErrors.add(req,"bad3");	
		}
		else if(e.equals("")){
			SessionErrors.add(req,"bad4");
		}
		else if(psw.equals("")){
			SessionErrors.add(req,"bad5");
		}
		else if(rpsw.equals("")){
			SessionErrors.add(req,"bad6");
		}
		else if(!psw.equals(rpsw)){
			SessionErrors.add(req,"nopass");
		}
		else{
			long id=CounterLocalServiceUtil.increment();
			User utente=UserLocalServiceUtil.createUser(id);
			utente.setFirstName(n);
			utente.setLastName(c);
			utente.setScreenName(u);
			utente.setPassword(psw);
			utente.setEmailAddress(e);
			try {
				UserLocalServiceUtil.addUser(utente);
			}
			catch (SystemException e2) {
				e2.printStackTrace();
	        }
			p.setValue("user",u);
			p.store();
			SessionMessages.add(req,"ok");
			res.setRenderParameter("jspPage","/html/prova/edit.jsp");
		}
	}


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);
thumbnail
Jan Geißler, módosítva 11 év-val korábban

RE: Custom Registration Portlet

Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
Try addUser(many many parameters)
Valerio Stark, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
I have tried with this:

ThemeDisplay theme= (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
			long creatorUserId = theme.getUserId(); // default liferay user
			long companyId = theme.getCompanyId(); // default company
			boolean autoPassword = false;
			String password2 = "";
			boolean autoScreenName = false;
			long facebookId = 0;
		    String openId = "";
			Locale locale = theme.getLocale();
			String middleName = "";
			int prefixId = 0;
			int suffixId = 0;
		    boolean male = true;    
			int birthdayMonth = 10;
			int birthdayDay = 10;
			int birthdayYear = 2010;
			String jobTitle = "";
			long[] groupIds = null;
			long[] organizationIds = null;
			long[] roleIds = null;
			long[] userGroupIds = null;
			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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

Expert Bejegyzések: 268 Csatlakozás dátuma: 2011.03.04. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
I have use psw and not password1 because with

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


I catch value from the form
Valerio Stark, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
Obiouvsly I have done also this:

try {
				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));
			}
			catch (SystemException e2) {
				e2.printStackTrace();
	        }
Matt S., módosítva 11 év-val korábban

RE: Custom Registration Portlet

Junior Member Bejegyzések: 36 Csatlakozás dátuma: 2012.11.29. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
Please, can help me?
Siby Mathew, módosítva 11 év-val korábban

RE: Custom Registration Portlet

Expert Bejegyzések: 268 Csatlakozás dátuma: 2011.03.04. Legújabb bejegyzések
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., módosítva 11 év-val korábban

RE: Custom Registration Portlet

Junior Member Bejegyzések: 36 Csatlakozás dátuma: 2012.11.29. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
I have insert same psw but the answer is the same: Your request failed to complete

What I have to do?
Siby Mathew, módosítva 11 év-val korábban

RE: Custom Registration Portlet

Expert Bejegyzések: 268 Csatlakozás dátuma: 2011.03.04. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
I think that I needn't to a debug because this is my code:

ThemeDisplay theme= (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
			long creatorUserId = theme.getUserId(); // default liferay user
			long companyId = theme.getCompanyId(); // default company
			boolean autoPassword = true;
			boolean autoScreenName = true;
			long facebookId = 0;
		    String openId = "";
			Locale locale = theme.getLocale();
			String middleName = "";
			int prefixId = 0;
			int suffixId = 0;
		    boolean male = true;    
			int birthdayMonth = 10;
			int birthdayDay = 10;
			int birthdayYear = 2010;
			String jobTitle = "";
			long[] groupIds = null;
			long[] organizationIds = null;
			long[] roleIds = null;
			long[] userGroupIds = null;
			boolean sendEmail = false;
			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:

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));


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

So I have tried to do this:


long id=CounterLocalServiceUtil.increment();
			User utente=UserLocalServiceUtil.createUser(id);
			utente.setFirstName(n);
			utente.setLastName(c);
			utente.setScreenName(u);
			utente.setPassword(psw);
			utente.setEmailAddress(e);
			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:


long id=CounterLocalServiceUtil.increment();
			User utente=UserLocalServiceUtil.createUser(id);
			utente.setFirstName(n);
			utente.setLastName(c);
			utente.setScreenName(u);
			utente.setPassword(psw);
			utente.setEmailAddress(e);
try {
				UserLocalServiceUtil.addUser(utente);
			}
			catch (SystemException e2) {
				e2.printStackTrace();
	        }


The same!

What I have to do? Why user don't is added in database?
Siby Mathew, módosítva 11 év-val korábban

RE: Custom Registration Portlet

Expert Bejegyzések: 268 Csatlakozás dátuma: 2011.03.04. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
Ok now I try.
Before I have tried another thing:

System.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., módosítva 11 év-val korábban

RE: Custom Registration Portlet

Junior Member Bejegyzések: 36 Csatlakozás dátuma: 2012.11.29. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
Up. Please I have very much problems emoticon
Siby Mathew, módosítva 11 év-val korábban

RE: Custom Registration Portlet

Expert Bejegyzések: 268 Csatlakozás dátuma: 2011.03.04. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Custom Registration Portlet

New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.01.07. Legújabb bejegyzések
I have difficult to do debugging. I have put as breakpoint code after try. But I don't know how help you to understand