|
|
@ -128,7 +128,7 @@ public class UserService implements UserDetailsService {
|
|
|
|
throw new UserEmailExistsException(userDto.getEmail());
|
|
|
|
throw new UserEmailExistsException(userDto.getEmail());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!userDto.isPasswordsValid()) {
|
|
|
|
if (!userDto.isPasswordsValid()) {
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException();
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
User user = userMapper.userDtoToUserEntity(userDto);
|
|
|
|
User user = userMapper.userDtoToUserEntity(userDto);
|
|
|
|
user.setActivated(false);
|
|
|
|
user.setActivated(false);
|
|
|
@ -198,10 +198,10 @@ public class UserService implements UserDetailsService {
|
|
|
|
: roles);
|
|
|
|
: roles);
|
|
|
|
if (!StringUtils.isEmpty(userDto.getOldPassword())) {
|
|
|
|
if (!StringUtils.isEmpty(userDto.getOldPassword())) {
|
|
|
|
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
|
|
|
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException();
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
|
|
|
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException();
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
|
|
|
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
|
|
|
log.debug("Changed password for User: {}", user.getLogin());
|
|
|
|
log.debug("Changed password for User: {}", user.getLogin());
|
|
|
@ -221,24 +221,18 @@ public class UserService implements UserDetailsService {
|
|
|
|
return userMapper.userEntityToUserDto(user);
|
|
|
|
return userMapper.userEntityToUserDto(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public UserDto changeUserPassword(UserDto userDto) {
|
|
|
|
public void changeUserPassword(User user, Map<String, String> payload) {
|
|
|
|
if (userDto.getId() == null) {
|
|
|
|
if (!payload.get("password").equals(payload.get("confirmPassword"))) {
|
|
|
|
throw new EntityIdIsNullException();
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
|
|
|
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
final String login = UserUtils.getCurrentUserLogin();
|
|
|
|
|
|
|
|
final User user = userRepository.findOneByLoginIgnoreCase(login);
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
throw new UserNotFoundException(login);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
|
|
|
if (!passwordEncoder.matches(payload.get("oldPassword"), user.getPassword())) {
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException();
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException("Старый пароль введен неправильно");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
|
|
|
user.setPassword(passwordEncoder.encode(payload.get("password")));
|
|
|
|
log.debug("Changed password for User: {}", user.getLogin());
|
|
|
|
log.debug("Changed password for User: {}", user.getLogin());
|
|
|
|
return userMapper.userEntityToUserDto(userRepository.save(user));
|
|
|
|
userRepository.save(user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mailService.sendChangePasswordMail(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean requestUserPasswordReset(String email) {
|
|
|
|
public boolean requestUserPasswordReset(String email) {
|
|
|
@ -259,7 +253,7 @@ public class UserService implements UserDetailsService {
|
|
|
|
|
|
|
|
|
|
|
|
public boolean completeUserPasswordReset(String key, UserResetPasswordDto userResetPasswordDto) {
|
|
|
|
public boolean completeUserPasswordReset(String key, UserResetPasswordDto userResetPasswordDto) {
|
|
|
|
if (!userResetPasswordDto.isPasswordsValid()) {
|
|
|
|
if (!userResetPasswordDto.isPasswordsValid()) {
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException();
|
|
|
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
User user = userRepository.findOneByResetKey(key);
|
|
|
|
User user = userRepository.findOneByResetKey(key);
|
|
|
|
if (user == null) {
|
|
|
|
if (user == null) {
|
|
|
|