Fix: Passwort-Änderung wirft Whitelabel-Error
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) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
@@ -133,25 +134,25 @@ public class ProfileController {
|
|||||||
public String changePassword(@RequestParam("oldPassword") String oldPassword,
|
public String changePassword(@RequestParam("oldPassword") String oldPassword,
|
||||||
@RequestParam("newPassword") String newPassword,
|
@RequestParam("newPassword") String newPassword,
|
||||||
Principal principal,
|
Principal principal,
|
||||||
Model model) {
|
RedirectAttributes redirectAttributes) {
|
||||||
String username = principal.getName();
|
String username = principal.getName();
|
||||||
User user = userService.findByUsername(username);
|
User user = userService.findByUsername(username);
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
model.addAttribute("error", "Benutzer nicht gefunden.");
|
redirectAttributes.addFlashAttribute("error", "Benutzer nicht gefunden.");
|
||||||
return "profile";
|
return "redirect:/profile/settings";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passwordEncoder.matches(oldPassword, user.getPassword())) {
|
if (!passwordEncoder.matches(oldPassword, user.getPassword())) {
|
||||||
model.addAttribute("error", "Das aktuelle Passwort ist falsch.");
|
redirectAttributes.addFlashAttribute("error", "Das aktuelle Passwort ist falsch.");
|
||||||
return "profile";
|
return "redirect:/profile/settings";
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setPassword(passwordEncoder.encode(newPassword));
|
user.setPassword(passwordEncoder.encode(newPassword));
|
||||||
userService.save(user);
|
userService.save(user);
|
||||||
|
|
||||||
model.addAttribute("message", "Passwort erfolgreich geändert.");
|
redirectAttributes.addFlashAttribute("message", "Passwort erfolgreich geändert.");
|
||||||
return "profile";
|
return "redirect:/profile/settings";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/profile/delete")
|
@PostMapping("/profile/delete")
|
||||||
|
|||||||
@@ -29,6 +29,14 @@
|
|||||||
<h1 style="color:var(--heading); font-size:1.9rem; font-weight:800; margin:.3rem 0 .25rem;">⚙️ Einstellungen</h1>
|
<h1 style="color:var(--heading); font-size:1.9rem; font-weight:800; margin:.3rem 0 .25rem;">⚙️ Einstellungen</h1>
|
||||||
<p style="color:var(--muted); margin-bottom:1.4rem;">Passe Mindflux nach deinen Wünschen an</p>
|
<p style="color:var(--muted); margin-bottom:1.4rem;">Passe Mindflux nach deinen Wünschen an</p>
|
||||||
|
|
||||||
|
<!-- Flash-Meldungen (z. B. nach Passwortänderung) -->
|
||||||
|
<div th:if="${message}" class="mf-panel accent mf-success" style="margin-bottom:1.2rem;">
|
||||||
|
<p th:text="${message}" style="color:var(--accent); margin:0;"></p>
|
||||||
|
</div>
|
||||||
|
<div th:if="${error}" class="mf-panel mf-error" style="margin-bottom:1.2rem;">
|
||||||
|
<p th:text="${error}" style="color:#c0392b; margin:0;"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Theme-Einstellung (Dummy) -->
|
<!-- Theme-Einstellung (Dummy) -->
|
||||||
<section class="mf-panel" style="margin-bottom:1.2rem;">
|
<section class="mf-panel" style="margin-bottom:1.2rem;">
|
||||||
<h2 class="mf-section-title">Theme wechseln</h2>
|
<h2 class="mf-section-title">Theme wechseln</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user