Fix password updation

This commit is contained in:
Anthony Stirling 2023-08-19 12:50:49 +01:00
parent 87ac245341
commit 505855a53c
2 changed files with 14 additions and 5 deletions

View file

@ -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);

View file

@ -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
}
});
});
</script>