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 @@ -