Add reset password endpoint and DTO

Introduces a new /reset-password endpoint in AuthenticationController, a ResetPasswordDTO for request payload, and a resetPassword method in UserService to handle password resets. Also updates SecurityURI with the new endpoint constant.
dev-pending-01-01-2026
Naeem Ullah 4 weeks ago
parent 44707f34c2
commit 1639058e20

@ -5,4 +5,5 @@ public interface SecurityURI {
String LOGIN = "/login";
String REGISTER = "/signup";
String CHANGE_PASSWORD = "/change-password";
String RESET_PASSWORD = "/reset-password";
}

@ -4,6 +4,7 @@ import com.mfsys.aconnect.security.constant.SecurityURI;
import com.mfsys.aconnect.security.dto.ChangePasswordDTO;
import com.mfsys.aconnect.security.dto.LoginRequest;
import com.mfsys.aconnect.security.dto.LoginResponse;
import com.mfsys.aconnect.security.dto.ResetPasswordDTO;
import com.mfsys.aconnect.security.service.AuthenticationService;
import com.mfsys.aconnect.usermanagement.constant.UserManagementURI;
import com.mfsys.aconnect.usermanagement.dto.UserDTOs;
@ -58,4 +59,13 @@ public class AuthenticationController {
return new ResponseEntity<>(response, HttpStatus.OK);
}
@PostMapping(SecurityURI.RESET_PASSWORD)
public ResponseEntity<Map<String, String>> resetPassword(@RequestBody ResetPasswordDTO request) {
String message = userService.resetPassword(request);
Map<String, String> response = new HashMap<>();
response.put("message", message);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}

@ -0,0 +1,10 @@
package com.mfsys.aconnect.security.dto;
import lombok.Data;
@Data
public class ResetPasswordDTO {
private String userId;
private String porOrgacode;
private String newPassword;
}

@ -1,6 +1,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.OldPasswordNotMatch;
import com.mfsys.aconnect.usermanagement.exceptions.UsernameAlreadyExistException;
@ -59,6 +60,16 @@ public class UserService {
return "Password changed successfully";
}
@Transactional
public String resetPassword(ResetPasswordDTO request) {
User user = userRepository.findById(request.getUserId())
.orElseThrow(() -> new EntityNotFoundException("User not found with ID: " + request.getUserId()));
user.setPassword(passwordEncryptionService.hashPassword(request.getNewPassword()));
userRepository.save(user);
return "Password changed successfully";
}
public List<UserDTOs.UserResponse> getAllUsers() {
return userRepository.findAll().stream()
.map(this::mapToResponseDTO)

Loading…
Cancel
Save