Fix password updation
This commit is contained in:
parent
87ac245341
commit
505855a53c
2 changed files with 14 additions and 5 deletions
|
@ -30,9 +30,6 @@ public class UserController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
public String register(@RequestParam String username, @RequestParam String password, Model model) {
|
public String register(@RequestParam String username, @RequestParam String password, Model model) {
|
||||||
if(userService.usernameExists(username)) {
|
if(userService.usernameExists(username)) {
|
||||||
|
@ -90,7 +87,7 @@ public class UserController {
|
||||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Current password is incorrect.");
|
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
|
// Logout using Spring's utility
|
||||||
new SecurityContextLogoutHandler().logout(request, response, null);
|
new SecurityContextLogoutHandler().logout(request, response, null);
|
||||||
|
|
|
@ -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>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue