diff --git a/src/main/java/com/example/mindflux/controller/ProfileController.java b/src/main/java/com/example/mindflux/controller/ProfileController.java index 68eaa26..991232d 100644 --- a/src/main/java/com/example/mindflux/controller/ProfileController.java +++ b/src/main/java/com/example/mindflux/controller/ProfileController.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -133,25 +134,25 @@ public class ProfileController { public String changePassword(@RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword") String newPassword, Principal principal, - Model model) { + RedirectAttributes redirectAttributes) { String username = principal.getName(); User user = userService.findByUsername(username); if (user == null) { - model.addAttribute("error", "Benutzer nicht gefunden."); - return "profile"; + redirectAttributes.addFlashAttribute("error", "Benutzer nicht gefunden."); + return "redirect:/profile/settings"; } if (!passwordEncoder.matches(oldPassword, user.getPassword())) { - model.addAttribute("error", "Das aktuelle Passwort ist falsch."); - return "profile"; + redirectAttributes.addFlashAttribute("error", "Das aktuelle Passwort ist falsch."); + return "redirect:/profile/settings"; } user.setPassword(passwordEncoder.encode(newPassword)); userService.save(user); - model.addAttribute("message", "Passwort erfolgreich geändert."); - return "profile"; + redirectAttributes.addFlashAttribute("message", "Passwort erfolgreich geändert."); + return "redirect:/profile/settings"; } @PostMapping("/profile/delete") diff --git a/src/main/resources/templates/settings.html b/src/main/resources/templates/settings.html index 8844d1b..ea6b853 100644 --- a/src/main/resources/templates/settings.html +++ b/src/main/resources/templates/settings.html @@ -29,6 +29,14 @@
Passe Mindflux nach deinen Wünschen an
+ +