From 52fe77a5b459e846433037e8724de410317119ee Mon Sep 17 00:00:00 2001 From: s-morimoto Date: Thu, 24 Sep 2026 10:12:02 +0900 Subject: [PATCH] =?UTF-8?q?[EDIT]=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC?= =?UTF-8?q?=E3=83=89=E5=86=8D=E8=A8=AD=E5=AE=9A=E3=81=AE=E3=83=90=E3=82=B0?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AuthenticationServiceImpl.java | 21 +----- .../controller/PasswordResetController.java | 67 ++++++++++++------- .../resources/templates/password_reset.html | 4 +- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/AuthenticationServiceImpl.java index c95c7d9..89ac9f4 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/AuthenticationServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/AuthenticationServiceImpl.java @@ -24,38 +24,19 @@ public class AuthenticationServiceImpl implements AuthenticationService { .orElse(null); if (userEntity == null) { - System.out.println("ユーザーなし"); return null; } - System.out.println("DB質問ID=" - + userEntity.getQuestionEntity().getSecretQuestionId()); - - System.out.println("入力質問ID=" - + authenticationForm.getSecretQuestionId()); - if (!userEntity.getQuestionEntity().getSecretQuestionId() .equals(authenticationForm.getSecretQuestionId())) { - - System.out.println("質問ID不一致"); return null; } - System.out.println("DB回答=[" - + userEntity.getSecretQuestionAnswer() + "]"); - - System.out.println("入力回答=[" - + authenticationForm.getSecretAnswer() + "]"); - if (!userEntity.getSecretQuestionAnswer() .equals(authenticationForm.getSecretAnswer())) { - - System.out.println("回答不一致"); return null; } - System.out.println("認証OK"); - return new AuthenticationModel(userEntity.getUserId()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/example/demo/app/presentation/controller/PasswordResetController.java b/src/main/java/com/example/demo/app/presentation/controller/PasswordResetController.java index 53d6699..0cba26f 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/PasswordResetController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/PasswordResetController.java @@ -7,6 +7,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.service.PasswordResetService; import com.example.demo.app.presentation.form.PasswordResetForm; @@ -25,29 +26,45 @@ public class PasswordResetController { @PostMapping("/password/reset") public String resetPassword( - PasswordResetForm passwordResetForm, - Model model, - HttpSession session){ - - Long userId = - (Long) session.getAttribute("passwordResetUserId"); - - if(userId == null) { - return "redirect:/login"; - } - - boolean isReset = - passwordResetService.resetPassword(userId, passwordResetForm); - - if(!isReset) { - model.addAttribute("Message", "パスワードが一致しません。"); - return "password_reset"; - } - - session.removeAttribute("passwordResetUserId"); - - return "redirect:/login"; + PasswordResetForm passwordResetForm, + Model model, + HttpSession session){ + + Long userId = + (Long) session.getAttribute("passwordResetUserId"); + + if (userId == null) { + LoginModel loginUser = + (LoginModel) session.getAttribute("loginUser"); + + if (loginUser != null) { + userId = loginUser.getUserId(); + } + } + + if (userId == null) { + return "redirect:/login"; + } + + boolean isReset = + passwordResetService.resetPassword(userId, passwordResetForm); + + System.out.println("isReset=" + isReset); + + if(!isReset) { + model.addAttribute("Message", "パスワードが一致しません。"); + return "password_reset"; + } + + session.removeAttribute("passwordResetUserId"); + + LoginModel loginUser = + (LoginModel) session.getAttribute("loginUser"); + + if (loginUser != null) { + return "redirect:/menu"; + } + + return "redirect:/login"; } -} - - +} \ No newline at end of file diff --git a/src/main/resources/templates/password_reset.html b/src/main/resources/templates/password_reset.html index a9fd287..b2abc42 100644 --- a/src/main/resources/templates/password_reset.html +++ b/src/main/resources/templates/password_reset.html @@ -36,8 +36,8 @@ -
-

+
+