diff --git a/src/main/java/stirling/software/SPDF/controller/api/UserController.java b/src/main/java/stirling/software/SPDF/controller/api/UserController.java index cd1be5a0..5cce1cc0 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/UserController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/UserController.java @@ -29,9 +29,6 @@ public class UserController { @Autowired private UserService userService; - - @Autowired - private PasswordEncoder passwordEncoder; @PostMapping("/register") public String register(@RequestParam String username, @RequestParam String password, Model model) { @@ -90,7 +87,7 @@ public class UserController { return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Current password is incorrect."); } - userService.changePassword(user, passwordEncoder.encode(newPassword)); + userService.changePassword(user, newPassword); // Logout using Spring's utility new SecurityContextLogoutHandler().logout(request, response, null); diff --git a/src/main/resources/templates/account.html b/src/main/resources/templates/account.html index 9d7c0ef6..ceba9cc4 100644 --- a/src/main/resources/templates/account.html +++ b/src/main/resources/templates/account.html @@ -155,7 +155,19 @@ } - + document.addEventListener("DOMContentLoaded", function() { + const form = document.querySelector('form[action="/change-password"]'); + + form.addEventListener('submit', function(event) { + const newPassword = document.getElementById('newPassword').value; + const confirmNewPassword = document.getElementById('confirmNewPassword').value; + + if (newPassword !== confirmNewPassword) { + alert('New Password and Confirm New Password must match.'); + event.preventDefault(); // Prevent form submission + } + }); + });