use of org.motechproject.mots.domain.security.User in project mots by motech-implementations.
the class UserService method editUserProfile.
/**
* Save User Profile with new encoded password (if it's not blank).
*
* @param userProfileDto User Profile to be updated.
* @return saved User
*/
public User editUserProfile(UUID userId, final UserProfileDto userProfileDto) {
User existingUser = getUser(userId);
final boolean encodeNewPassword = !StringUtils.isEmpty(userProfileDto.getPassword());
if (encodeNewPassword) {
changeUserPassword(existingUser.getUsername(), userProfileDto.getNewPassword(), userProfileDto.getPassword());
}
userMapper.updateFromUserProfileDto(userProfileDto, existingUser);
return userRepository.save(existingUser);
}
use of org.motechproject.mots.domain.security.User in project mots by motech-implementations.
the class UserService method changeUserPassword.
/**
* Updates user's password.
*
* @param username of user which password is about to change.
* @param newPassword is new password value for user.
* @param currentPassword is current user's password.
*/
public void changeUserPassword(String username, String newPassword, String currentPassword) {
User user = getUserByUserName(username);
if (!passwordsMatch(currentPassword, user.getPassword())) {
throw new IllegalArgumentException("Current password is incorrect.");
}
String newPasswordEncoded = new BCryptPasswordEncoder().encode(newPassword);
user.setPassword(newPasswordEncoded);
userRepository.save(user);
}
Aggregations