[EDIT]パスワード再設定のバグ修正

This commit is contained in:
2026-09-24 10:12:02 +09:00
parent ac85c2dc23
commit 52fe77a5b4
3 changed files with 45 additions and 47 deletions

View File

@@ -24,38 +24,19 @@ public class AuthenticationServiceImpl implements AuthenticationService {
.orElse(null); .orElse(null);
if (userEntity == null) { if (userEntity == null) {
System.out.println("ユーザーなし");
return null; return null;
} }
System.out.println("DB質問ID="
+ userEntity.getQuestionEntity().getSecretQuestionId());
System.out.println("入力質問ID="
+ authenticationForm.getSecretQuestionId());
if (!userEntity.getQuestionEntity().getSecretQuestionId() if (!userEntity.getQuestionEntity().getSecretQuestionId()
.equals(authenticationForm.getSecretQuestionId())) { .equals(authenticationForm.getSecretQuestionId())) {
System.out.println("質問ID不一致");
return null; return null;
} }
System.out.println("DB回答=["
+ userEntity.getSecretQuestionAnswer() + "]");
System.out.println("入力回答=["
+ authenticationForm.getSecretAnswer() + "]");
if (!userEntity.getSecretQuestionAnswer() if (!userEntity.getSecretQuestionAnswer()
.equals(authenticationForm.getSecretAnswer())) { .equals(authenticationForm.getSecretAnswer())) {
System.out.println("回答不一致");
return null; return null;
} }
System.out.println("認証OK");
return new AuthenticationModel(userEntity.getUserId()); return new AuthenticationModel(userEntity.getUserId());
} }
} }

View File

@@ -7,6 +7,7 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; 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.domain.service.PasswordResetService;
import com.example.demo.app.presentation.form.PasswordResetForm; import com.example.demo.app.presentation.form.PasswordResetForm;
@@ -32,13 +33,24 @@ public class PasswordResetController {
Long userId = Long userId =
(Long) session.getAttribute("passwordResetUserId"); (Long) session.getAttribute("passwordResetUserId");
if(userId == null) { if (userId == null) {
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
if (loginUser != null) {
userId = loginUser.getUserId();
}
}
if (userId == null) {
return "redirect:/login"; return "redirect:/login";
} }
boolean isReset = boolean isReset =
passwordResetService.resetPassword(userId, passwordResetForm); passwordResetService.resetPassword(userId, passwordResetForm);
System.out.println("isReset=" + isReset);
if(!isReset) { if(!isReset) {
model.addAttribute("Message", "パスワードが一致しません。"); model.addAttribute("Message", "パスワードが一致しません。");
return "password_reset"; return "password_reset";
@@ -46,8 +58,13 @@ public class PasswordResetController {
session.removeAttribute("passwordResetUserId"); session.removeAttribute("passwordResetUserId");
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
if (loginUser != null) {
return "redirect:/menu";
}
return "redirect:/login"; return "redirect:/login";
} }
} }

View File

@@ -36,8 +36,8 @@
<button type="submit">再設定</button> <button type="submit">再設定</button>
</form> </form>
<div th:if="${errorMessage}"> <div th:if="${Message}">
<p th:text="${errorMessage}"></p> <p th:text="${Message}"></p>
</div> </div>
</main> </main>
</body> </body>