From 7cb6621d1bb47bf41b3db6f8c4470f7611a8497d Mon Sep 17 00:00:00 2001 From: AliceDarkest Date: Fri, 26 Jun 2026 15:07:53 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Passwort-=C3=84nderung=20wirft=20Whitela?= =?UTF-8?q?bel-Error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ProfileController.changePassword gab "profile" zurück, ohne das von profile.html benötigte Model-Attribut `user` zu setzen -> Template-Rendering schlug fehl (500/Whitelabel). Zudem lag das Formular auf der settings-Seite. - changePassword nutzt jetzt PRG: Redirect auf /profile/settings mit Flash-Attributen (message/error) statt direktem View-Return. - settings.html zeigt die Flash-Meldungen (Erfolg/Fehler) an. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../mindflux/controller/ProfileController.java | 15 ++++++++------- src/main/resources/templates/settings.html | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) 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 @@

⚙️ Einstellungen

Passe Mindflux nach deinen Wünschen an

+ +
+

+
+
+

+
+

Theme wechseln