Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Nicolas Parvais
How to change user portrait from my portlet
7 febbraio 2012 1.31
Risposta

Nicolas Parvais

Punteggio: New Member

Messaggi: 4

Data di Iscrizione: 10 ottobre 2011

Messaggi recenti

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 :
 1
 2UserServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
 3
 4InputStream inputStream = uploadPortletRequest.getFileAsStream(
 5                        PROFILE_IMAGE);
 6
 7                if (Validator.isNotNull(inputStream)) {
 8                    _log.info("Update profile portrait");
 9                    byte[] bytes = FileUtil.getBytes(inputStream);
10                    _log.info("Image bytes [" + bytes + "]");
11
12                    UserServiceUtil.updatePortrait(user.getUserId(), bytes);
13}


What am I doing wrong ?

Best regard.
Nicolas.
David H Nebinger
RE: How to change user portrait from my portlet
7 febbraio 2012 5.07
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11305

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

Have you tried using the UserLocalServiceUtil class instead?
Hitoshi Ozawa
RE: How to change user portrait from my portlet
7 febbraio 2012 5.24
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7949

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

This has recently been solved in the following thread.

http://www.liferay.com/community/forums/-/message_boards/message/12390208
Nicolas Parvais
RE: How to change user portrait from my portlet
8 febbraio 2012 5.44
Risposta

Nicolas Parvais

Punteggio: New Member

Messaggi: 4

Data di Iscrizione: 10 ottobre 2011

Messaggi recenti

I already test using LocalService but it doesn't work.

Any other idea ?

Regards.
Hitoshi Ozawa
RE: How to change user portrait from my portlet
9 febbraio 2012 15.54
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7949

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

Have you tried using the code provided in the thread above?

Also, are you getting the same error message when using UserLocalServiceUtil?
Nicolas Parvais
RE: How to change user portrait from my portlet
10 febbraio 2012 0.50
Risposta

Nicolas Parvais

Punteggio: New Member

Messaggi: 4

Data di Iscrizione: 10 ottobre 2011

Messaggi recenti

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
RE: How to change user portrait from my portlet
10 febbraio 2012 2.19
Risposta

Nicolas Parvais

Punteggio: New Member

Messaggi: 4

Data di Iscrizione: 10 ottobre 2011

Messaggi recenti

Finally, we found why it doesn't work in our portlet.

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

 1
 2User user;
 3        try {
 4            user = PortalUtil.getSelectedUser(uploadPortletRequest);
 5            _log.info("Update profile [" + user.getUserId() + "]");
 6            if(Validator.isNotNull(user))
 7            {
 8                String firstName = ParamUtil.getString(uploadPortletRequest, PROFILE_FIRSTNAME);
 9                String lastName = ParamUtil.getString(uploadPortletRequest, PROFILE_LASTNAME);
10                String emailAddress = ParamUtil.getString(uploadPortletRequest, PROFILE_EMAILADDRESS);
11                String newPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_NEWPASSWORD);
12                String confirmPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_CONFIRMPASSWORD);
13                if(Validator.isNotNull(firstName))
14                    user.setFirstName(firstName);
15                if(Validator.isNotNull(lastName))
16                    user.setLastName(lastName);
17                if(Validator.isNotNull(emailAddress))
18                    user.setEmailAddress(emailAddress);
19                InputStream inputStream = uploadPortletRequest.getFileAsStream(
20                        PROFILE_IMAGE);
21                if (Validator.isNotNull(inputStream)) {
22                    _log.info("Update profile portrait");
23                    byte[] bytes = FileUtil.getBytes(inputStream);
24                    _log.info("Image bytes [" + bytes + "]");
25
26                    UserLocalServiceUtil.updatePortrait(user.getUserId(), bytes);
27                }
28                if(Validator.isNotNull(newPassword))
29                {
30                    if(Validator.isNotNull(confirmPassword) && confirmPassword.equals(newPassword))
31                    {
32                        _log.info("Update password [" + newPassword + "] + [" + confirmPassword + "]");
33                        UserLocalServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
34                    } else {
35                        SessionErrors.add(request, "profile-wrong-password");
36                    }
37                }
38                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
RE: How to change user portrait from my portlet
17 maggio 2012 5.05
Risposta

ronnie orvakanti

Punteggio: Junior Member

Messaggi: 27

Data di Iscrizione: 27 febbraio 2012

Messaggi recenti

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 :

 1
 2User user;
 3        try {
 4            user = PortalUtil.getSelectedUser(uploadPortletRequest);
 5            _log.info("Update profile [" + user.getUserId() + "]");
 6            if(Validator.isNotNull(user))
 7            {
 8                String firstName = ParamUtil.getString(uploadPortletRequest, PROFILE_FIRSTNAME);
 9                String lastName = ParamUtil.getString(uploadPortletRequest, PROFILE_LASTNAME);
10                String emailAddress = ParamUtil.getString(uploadPortletRequest, PROFILE_EMAILADDRESS);
11                String newPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_NEWPASSWORD);
12                String confirmPassword = ParamUtil.getString(uploadPortletRequest, PROFILE_CONFIRMPASSWORD);
13                if(Validator.isNotNull(firstName))
14                    user.setFirstName(firstName);
15                if(Validator.isNotNull(lastName))
16                    user.setLastName(lastName);
17                if(Validator.isNotNull(emailAddress))
18                    user.setEmailAddress(emailAddress);
19                InputStream inputStream = uploadPortletRequest.getFileAsStream(
20                        PROFILE_IMAGE);
21                if (Validator.isNotNull(inputStream)) {
22                    _log.info("Update profile portrait");
23                    byte[] bytes = FileUtil.getBytes(inputStream);
24                    _log.info("Image bytes [" + bytes + "]");
25
26                    UserLocalServiceUtil.updatePortrait(user.getUserId(), bytes);
27                }
28                if(Validator.isNotNull(newPassword))
29                {
30                    if(Validator.isNotNull(confirmPassword) && confirmPassword.equals(newPassword))
31                    {
32                        _log.info("Update password [" + newPassword + "] + [" + confirmPassword + "]");
33                        UserLocalServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
34                    } else {
35                        SessionErrors.add(request, "profile-wrong-password");
36                    }
37                }
38                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?