Add first login password change endpoint

Introduced a new /first-login endpoint in AuthenticationController to handle password changes on first login. Added corresponding constant in SecurityURI and implemented firstLogin method in UserService to update password and firstLogin status.
dev-pending-20-01-2026-V2
Naeem Ullah 2 weeks ago
parent 53866feb45
commit 393fa16fa3

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

@ -55,6 +55,15 @@ public class AuthenticationController {
return new ResponseEntity<>(response, HttpStatus.OK); return new ResponseEntity<>(response, HttpStatus.OK);
} }
@PostMapping(SecurityURI.FIRST_LOGIN)
public ResponseEntity<Map<String, String>> firstLogin(@RequestBody ChangePasswordDTO request) {
String message = userService.firstLogin(request);
Map<String, String> response = new HashMap<>();
response.put("message", message);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@PostMapping(SecurityURI.RESET_PASSWORD) @PostMapping(SecurityURI.RESET_PASSWORD)
public ResponseEntity<Map<String, String>> resetPassword(@RequestBody ResetPasswordDTO request) { public ResponseEntity<Map<String, String>> resetPassword(@RequestBody ResetPasswordDTO request) {
String message = userService.resetPassword(request); String message = userService.resetPassword(request);

@ -61,6 +61,21 @@ public class UserService {
return "Password changed successfully"; return "Password changed successfully";
} }
@Transactional
public String firstLogin(ChangePasswordDTO request) {
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());
}
user.setPassword(passwordEncryptionService.hashPassword(request.getNewPassword()));
user.setFirstLogin(false);
userRepository.save(user);
return "Password changed successfully";
}
@Transactional @Transactional
public String resetPassword(ResetPasswordDTO request) { public String resetPassword(ResetPasswordDTO request) {
User user = userRepository.findById(request.getUserId()) User user = userRepository.findById(request.getUserId())

Loading…
Cancel
Save