diff --git a/src/main/java/com/pandoli365/bibimbap/controller/WebMvcController.java b/src/main/java/com/pandoli365/bibimbap/controller/WebMvcController.java index c62e8b4..25d431f 100644 --- a/src/main/java/com/pandoli365/bibimbap/controller/WebMvcController.java +++ b/src/main/java/com/pandoli365/bibimbap/controller/WebMvcController.java @@ -13,6 +13,7 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.Arrays; +import java.util.List; //이곳에서는 뷰만 제어 @Controller @@ -28,15 +29,20 @@ public class WebMvcController implements WebMvcConfigurer, ErrorController { return mv; } + /* ✅ 허용된 페이지 목록 */ + private static final List ALLOWED_PAGES = Arrays.asList( + "error", "login", "profile", "signup", "" + ); + @GetMapping("/{pageName}") public ModelAndView mainView(@PathVariable("pageName") String pageName, - @RequestParam(name = "id", required = false) String id, - HttpSession session, - HttpServletRequest request) { + @RequestParam(name = "id", required = false) String id, + HttpSession session, + HttpServletRequest request) { ModelAndView mv = new ModelAndView(); -// if (!ALLOWED_PAGES.contains(keyword)) { -// return new ModelAndView("redirect:/main"); -// } + if (!ALLOWED_PAGES.contains(pageName)) { + return new ModelAndView("redirect:/error"); + } switch (pageName) { case "error": mv.setViewName("/errer"); @@ -46,8 +52,17 @@ public class WebMvcController implements WebMvcConfigurer, ErrorController { } break; case "login": + if (isLoggedIn(session)) { + return new ModelAndView("redirect:/profile"); + } mv.setViewName("/login"); break; + case "profile": + if (!isLoggedIn(session)) { + return new ModelAndView("redirect:/login"); + } + mv.setViewName("/profile"); + break; case "signup": mv.setViewName("/signup"); break; @@ -59,6 +74,10 @@ public class WebMvcController implements WebMvcConfigurer, ErrorController { return mv; } + private boolean isLoggedIn(HttpSession session) { + return session != null && session.getAttribute("userId") != null; + } + /// 접속기기 모바일 확인 함수 private boolean isMobileDevice(HttpServletRequest request) { String userAgent = request.getHeader("User-Agent"); @@ -72,4 +91,4 @@ public class WebMvcController implements WebMvcConfigurer, ErrorController { // User-Agent 문자열이 모바일 기기를 포함하는지 검사 return Arrays.stream(mobileKeywords).anyMatch(userAgent::contains); } -} +} \ No newline at end of file diff --git a/src/main/java/com/pandoli365/bibimbap/controller/api/UserController.java b/src/main/java/com/pandoli365/bibimbap/controller/api/UserController.java index 544d0ed..c01ea18 100644 --- a/src/main/java/com/pandoli365/bibimbap/controller/api/UserController.java +++ b/src/main/java/com/pandoli365/bibimbap/controller/api/UserController.java @@ -204,6 +204,7 @@ public class UserController { session.setAttribute("status", user.getStatus()); session.setAttribute("authProvider", identity.getProvider()); session.setAttribute("authIdentityId", identity.getId()); + session.setAttribute("lastLoginAt", user.getLastLoginAt()); Map account = new LinkedHashMap<>(); account.put("id", user.getId()); @@ -214,6 +215,7 @@ public class UserController { account.put("status", user.getStatus()); account.put("authProvider", identity.getProvider()); account.put("authIdentityId", identity.getId()); + account.put("lastLoginAt", user.getLastLoginAt()); session.setAttribute("account", account); } diff --git a/src/main/webapp/WEB-INF/views/header.jsp b/src/main/webapp/WEB-INF/views/header.jsp index b5993ae..6c13361 100644 --- a/src/main/webapp/WEB-INF/views/header.jsp +++ b/src/main/webapp/WEB-INF/views/header.jsp @@ -1,5 +1,11 @@ <%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %> +<% + jakarta.servlet.http.HttpSession headerSession = request.getSession(false); + boolean headerLoggedIn = headerSession != null && headerSession.getAttribute("userId") != null; + String headerProfileHref = request.getContextPath() + (headerLoggedIn ? "/profile" : "/login"); + String headerProfileLabel = headerLoggedIn ? "프로필" : "로그인"; +%> + + + +
+
+
+

BIBIMBAP ACCOUNT

+

프로필

+
+ +
+
+ +
+

<%= displayName %>

+ +
+
+ +
+
+

권한

+

<%= role %>

+
+
+

상태

+

<%= status %>

+
+
+

로그인 방식

+

<%= authProvider %>

+
+
+

최근 로그인

+

<%= lastLoginAt %>

+
+
+ +
+ 홈으로 이동 +
+ +
+
+
+
+
+ + +