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.
Please sign in to flag this as inappropriate.