|
|
|
|
@ -3,6 +3,7 @@ package com.mfsys.aconnect.usermanagement.service;
|
|
|
|
|
import com.mfsys.aconnect.security.dto.ChangePasswordDTO;
|
|
|
|
|
import com.mfsys.aconnect.security.dto.ResetPasswordDTO;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.exceptions.EmailAlreadyExistException;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.exceptions.NewPasswordException;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.exceptions.OldPasswordNotMatch;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.exceptions.UsernameAlreadyExistException;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.model.Role;
|
|
|
|
|
@ -55,9 +56,8 @@ public class UserService {
|
|
|
|
|
User user = userRepository.findById(request.getUserId())
|
|
|
|
|
.orElseThrow(() -> new EntityNotFoundException("User not found with ID: " + request.getUserId()));
|
|
|
|
|
|
|
|
|
|
boolean isPasswordValid = PasswordEncryptionService.verifyPassword(request.getOldPassword(), user.getPassword());
|
|
|
|
|
if(!isPasswordValid) {
|
|
|
|
|
throw new OldPasswordNotMatch(request.getPorOrgacode());
|
|
|
|
|
if (passwordEncryptionService.matches(request.getNewPassword(), user.getPassword())) {
|
|
|
|
|
throw new NewPasswordException(request.getPorOrgacode());
|
|
|
|
|
}
|
|
|
|
|
user.setPassword(passwordEncryptionService.hashPassword(request.getNewPassword()));
|
|
|
|
|
userRepository.save(user);
|
|
|
|
|
@ -69,10 +69,9 @@ public class UserService {
|
|
|
|
|
User user = userRepository.findById(request.getUserId())
|
|
|
|
|
.orElseThrow(() -> new EntityNotFoundException("User not found with ID: " + request.getUserId()));
|
|
|
|
|
|
|
|
|
|
boolean isPasswordValid = PasswordEncryptionService.verifyPassword(request.getOldPassword(), user.getPassword());
|
|
|
|
|
if(!isPasswordValid) {
|
|
|
|
|
throw new OldPasswordNotMatch(request.getPorOrgacode());
|
|
|
|
|
}
|
|
|
|
|
if (passwordEncryptionService.matches(request.getNewPassword(), user.getPassword())) {
|
|
|
|
|
throw new NewPasswordException(request.getPorOrgacode());
|
|
|
|
|
}
|
|
|
|
|
user.setPassword(passwordEncryptionService.hashPassword(request.getNewPassword()));
|
|
|
|
|
user.setFirstLogin(false);
|
|
|
|
|
userRepository.save(user);
|
|
|
|
|
@ -84,6 +83,9 @@ public class UserService {
|
|
|
|
|
User user = userRepository.findById(request.getUserId())
|
|
|
|
|
.orElseThrow(() -> new EntityNotFoundException("User not found with ID: " + request.getUserId()));
|
|
|
|
|
|
|
|
|
|
if (passwordEncryptionService.matches(request.getNewPassword(), user.getPassword())) {
|
|
|
|
|
throw new NewPasswordException(request.getPorOrgacode());
|
|
|
|
|
}
|
|
|
|
|
user.setPassword(passwordEncryptionService.hashPassword(request.getNewPassword()));
|
|
|
|
|
userRepository.save(user);
|
|
|
|
|
return "Password changed successfully";
|
|
|
|
|
|