Merge pull request 'Fix: Passwort-Aenderung Whitelabel-Error' (#2) from fix/change-password into main
mindflux-ci / build (push) Successful in 26s

This commit was merged in pull request #2.
This commit is contained in:
2026-06-26 13:10:01 +00:00
2 changed files with 16 additions and 7 deletions
@@ -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>