Fórum

How to change user portrait from my portlet

Nicolas Parvais, modificado 12 Anos atrás.

How to change user portrait from my portlet

New Member Postagens: 4 Data de Entrada: 10/10/11 Postagens Recentes
I develop a portlet to allow user to change firstname, lastname, password and portrait.

Firstname and Lastname are changed as expected. But Password and portrait doesn't update.

I use same code that Liferay one :

UserServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);

InputStream inputStream = uploadPortletRequest.getFileAsStream(
						PROFILE_IMAGE);

				if (Validator.isNotNull(inputStream)) {
					_log.info("Update profile portrait");
					byte[] bytes = FileUtil.getBytes(inputStream);
					_log.info("Image bytes [" + bytes + "]");

					UserServiceUtil.updatePortrait(user.getUserId(), bytes);
}


What am I doing wrong ?

Best regard.
Nicolas.
thumbnail
David H Nebinger, modificado 12 Anos atrás.

RE: How to change user portrait from my portlet

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Have you tried using the UserLocalServiceUtil class instead?
thumbnail
Hitoshi Ozawa, modificado 12 Anos atrás.

RE: How to change user portrait from my portlet

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
This has recently been solved in the following thread.

http://www.liferay.com/community/forums/-/message_boards/message/12390208
Nicolas Parvais, modificado 12 Anos atrás.

RE: How to change user portrait from my portlet

New Member Postagens: 4 Data de Entrada: 10/10/11 Postagens Recentes
I already test using LocalService but it doesn't work.

Any other idea ?

Regards.
thumbnail
Hitoshi Ozawa, modificado 12 Anos atrás.

RE: How to change user portrait from my portlet

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Have you tried using the code provided in the thread above?

Also, are you getting the same error message when using UserLocalServiceUtil?
Nicolas Parvais, modificado 12 Anos atrás.

RE: How to change user portrait from my portlet

New Member Postagens: 4 Data de Entrada: 10/10/11 Postagens Recentes
Yes, I did it. But it doesn't solve the issue.

There is no errors in log file and I get a success message in my portlet, but password and portrait image do not change. Firstname and Lastname do !

Regards
Nicolas Parvais, modificado 12 Anos atrás.

RE: How to change user portrait from my portlet

New Member Postagens: 4 Data de Entrada: 10/10/11 Postagens Recentes
Finally, we found why it doesn't work in our portlet.

Here is the full code of the update of our profile information :


User user;
		try {
			user = PortalUtil.getSelectedUser(uploadPortletRequest);
			_log.info("Update profile [" + user.getUserId() + "]");
			if(Validator.isNotNull(user))
			{
				String firstName = ParamUtil.getString(uploadPortletRequest, PROFILE_FIRSTNAME);
				String lastName = ParamUtil.getString(uploadPortletRequest, PROFILE_LASTNAME);
				String emailAddress = ParamUtil.getString(uploadPortletRequest, PROFILE_EMAILADDRESS);
				String newPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_NEWPASSWORD);
				String confirmPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_CONFIRMPASSWORD);
				if(Validator.isNotNull(firstName))
					user.setFirstName(firstName);
				if(Validator.isNotNull(lastName))
					user.setLastName(lastName);
				if(Validator.isNotNull(emailAddress))
					user.setEmailAddress(emailAddress);
				InputStream inputStream = uploadPortletRequest.getFileAsStream(
						PROFILE_IMAGE);
				if (Validator.isNotNull(inputStream)) {
					_log.info("Update profile portrait");
					byte[] bytes = FileUtil.getBytes(inputStream);
					_log.info("Image bytes [" + bytes + "]");

					UserLocalServiceUtil.updatePortrait(user.getUserId(), bytes);
				}
				if(Validator.isNotNull(newPassword))
				{
					if(Validator.isNotNull(confirmPassword) && confirmPassword.equals(newPassword))
					{
						_log.info("Update password [" + newPassword + "] + [" + confirmPassword + "]");
						UserLocalServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
					} else {
						SessionErrors.add(request, "profile-wrong-password");
					}
				}
				UserLocalServiceUtil.updateUser(user);

First, we get the user based on is userid. After we update its portrait and is password. We set new Firstname, Lastname, email to the user we get first. And finally, we update this user. But we didn't change portrait and password from the user we get first. And then, the old password and old portrait overwrite the value modified in our method.
We just need to put updatePassword and updatePortrait outside the other updateUser process.

This works now.
ronnie orvakanti, modificado 11 Anos atrás.

RE: How to change user portrait from my portlet

Junior Member Postagens: 27 Data de Entrada: 27/02/12 Postagens Recentes
Nicolas Parvais:
Finally, we found why it doesn't work in our portlet.

Here is the full code of the update of our profile information :


User user;
		try {
			user = PortalUtil.getSelectedUser(uploadPortletRequest);
			_log.info("Update profile [" + user.getUserId() + "]");
			if(Validator.isNotNull(user))
			{
				String firstName = ParamUtil.getString(uploadPortletRequest, PROFILE_FIRSTNAME);
				String lastName = ParamUtil.getString(uploadPortletRequest, PROFILE_LASTNAME);
				String emailAddress = ParamUtil.getString(uploadPortletRequest, PROFILE_EMAILADDRESS);
				String newPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_NEWPASSWORD);
				String confirmPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_CONFIRMPASSWORD);
				if(Validator.isNotNull(firstName))
					user.setFirstName(firstName);
				if(Validator.isNotNull(lastName))
					user.setLastName(lastName);
				if(Validator.isNotNull(emailAddress))
					user.setEmailAddress(emailAddress);
				InputStream inputStream = uploadPortletRequest.getFileAsStream(
						PROFILE_IMAGE);
				if (Validator.isNotNull(inputStream)) {
					_log.info("Update profile portrait");
					byte[] bytes = FileUtil.getBytes(inputStream);
					_log.info("Image bytes [" + bytes + "]");

					UserLocalServiceUtil.updatePortrait(user.getUserId(), bytes);
				}
				if(Validator.isNotNull(newPassword))
				{
					if(Validator.isNotNull(confirmPassword) && confirmPassword.equals(newPassword))
					{
						_log.info("Update password [" + newPassword + "] + [" + confirmPassword + "]");
						UserLocalServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
					} else {
						SessionErrors.add(request, "profile-wrong-password");
					}
				}
				UserLocalServiceUtil.updateUser(user);

First, we get the user based on is userid. After we update its portrait and is password. We set new Firstname, Lastname, email to the user we get first. And finally, we update this user. But we didn't change portrait and password from the user we get first. And then, the old password and old portrait overwrite the value modified in our method.
We just need to put updatePassword and updatePortrait outside the other updateUser process.

This works now.


Hi Nicolas,
Do you know how to access a user profile picture?