diff --git a/book-rent/src/main/java/com/example/demo/config/CustomAuthenticationFailureHandler.java b/book-rent/src/main/java/com/example/demo/config/CustomAuthenticationFailureHandler.java index be6c000..9810c7f 100644 --- a/book-rent/src/main/java/com/example/demo/config/CustomAuthenticationFailureHandler.java +++ b/book-rent/src/main/java/com/example/demo/config/CustomAuthenticationFailureHandler.java @@ -14,46 +14,59 @@ import com.example.demo.service.LoginAttemptService; // ログイン失敗時の処理 @Component -public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { +public class CustomAuthenticationFailureHandler + extends SimpleUrlAuthenticationFailureHandler { - private LoginAttemptService loginAttemptService; + private final LoginAttemptService loginAttemptService; - public CustomAuthenticationFailureHandler(LoginAttemptService loginAttemptService) { - this.loginAttemptService = loginAttemptService; - } + public CustomAuthenticationFailureHandler( + LoginAttemptService loginAttemptService) { + this.loginAttemptService = loginAttemptService; + } - @Override - public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, - AuthenticationException exception) throws IOException, ServletException { + @Override + public void onAuthenticationFailure( + HttpServletRequest request, + HttpServletResponse response, + AuthenticationException exception) + throws IOException, ServletException { - // 画面から入力されたメールアドレスを取得 - String mailAddress = request.getParameter("mailAddress"); + // 画面から入力されたメールアドレスを取得 + String mailAddress = request.getParameter("mailAddress"); - if (mailAddress != null && !mailAddress.isBlank()) { - String mail = mailAddress.trim(); + // メールアドレスが空欄の場合 + if (mailAddress == null || mailAddress.isBlank()) { + getRedirectStrategy().sendRedirect( + request, response, "/login?error=empty"); + return; + } - if (loginAttemptService.isBlocked(mail)) { - getRedirectStrategy().sendRedirect( - request, response, "/login?error=locked"); - return; - } + String mail = mailAddress.trim(); - // 失敗回数を1増やす - loginAttemptService.loginFailed(mail); + // すでにロックされている場合 + if (loginAttemptService.isBlocked(mail)) { + getRedirectStrategy().sendRedirect( + request, response, "/login?error=locked"); + return; + } - // すでにロック中なら失敗回数を増やさない - if (loginAttemptService.isBlocked(mail)) { - getRedirectStrategy().sendRedirect( - request, response, "/login?error=locked"); - return; - } + // ログイン失敗回数を増やす + loginAttemptService.loginFailed(mail); - // あと何回失敗されるとロックされるか取得 - int remaining = loginAttemptService.getRemainingAttempts(mail); + // 失敗回数の上限に達した場合 + if (loginAttemptService.isBlocked(mail)) { + getRedirectStrategy().sendRedirect( + request, response, "/login?error=locked"); + return; + } - getRedirectStrategy().sendRedirect( - request, response, "/login?error=failed&remaining=" + remaining); - } + // 残りのログイン試行回数を取得 + int remaining = + loginAttemptService.getRemainingAttempts(mail); - } + getRedirectStrategy().sendRedirect( + request, response, + "/login?error=failed&remaining=" + remaining); + } } + \ No newline at end of file diff --git a/book-rent/src/main/resources/static/css/style.css b/book-rent/src/main/resources/static/css/style.css index 6a1a62f..c41bc01 100644 --- a/book-rent/src/main/resources/static/css/style.css +++ b/book-rent/src/main/resources/static/css/style.css @@ -126,4 +126,9 @@ th { background: #eaf4f6; } .page-number:hover { background: #d5edf1; +} +.page-number.active { + background: #176a78; + color: #fff; + border-color: #176a78; } \ No newline at end of file diff --git a/book-rent/src/main/resources/templates/bookList.html b/book-rent/src/main/resources/templates/bookList.html index 42ad7d3..3efd268 100644 --- a/book-rent/src/main/resources/templates/bookList.html +++ b/book-rent/src/main/resources/templates/bookList.html @@ -65,6 +65,7 @@ th:href="@{/books(page=${bookPage.number-1}, nmBook=${nmBook}, publisher=${publisher}, note=${note})}">前へ