-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
304 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
stockMate/src/main/java/com/stockm8/controller/ManagerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,68 @@ | ||
package com.stockm8.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.SessionAttribute; | ||
|
||
import com.stockm8.domain.dto.PendingUserDTO; | ||
import com.stockm8.domain.enums.UserRole; | ||
import com.stockm8.domain.vo.UserVO; | ||
import com.stockm8.service.UserService; | ||
|
||
@Controller | ||
@RequestMapping(value = "/manager/*") | ||
public class ManagerController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AdminController.class); | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
/** | ||
* 매니저 메인 페이지 표시(GET) | ||
* | ||
* @throws Exception | ||
* | ||
*/ | ||
// http://localhost:8088/admin/main | ||
@GetMapping("/main") | ||
public String managerMainGET(@SessionAttribute("userId") Long userId, Model model) throws Exception { | ||
logger.info("managerMainGET() 호출 - 페이지 접근 (userId: {})", userId); | ||
|
||
// userId로 사용자 정보 가져오기 | ||
UserVO user = userService.getUserById(userId); | ||
|
||
if (user != null) { | ||
// 관리자 여부 확인 (MANAGER인 경우) | ||
boolean isManager = user.getUserRole() == UserRole.MANAGER; | ||
model.addAttribute("isManager", isManager); // JSP에 전달할 데이터 | ||
} | ||
return "manager/main"; // 메인 페이지 반환 | ||
} | ||
|
||
// http://localhost:8088/manager/approve | ||
@GetMapping("/approve") | ||
public String managerApproveGET(@SessionAttribute("userId") Long userId, Model model) throws Exception { | ||
logger.info("managerApproveGET() 호출 - 페이지 접근 (userId: {})", userId); | ||
|
||
// userId로 사용자 정보 가져오기 | ||
UserVO user = userService.getUserById(userId); | ||
int businessId = user.getBusinessId(); | ||
|
||
// 조건에 맞는 사용자와 사업자 정보 가져오기 | ||
List<PendingUserDTO> pendingUsers = userService.getStaffByBusinessId(businessId); | ||
|
||
// JSP로 전달 | ||
model.addAttribute("pendingUsers", pendingUsers); | ||
|
||
return "admin/approve"; // JSP 페이지 반환 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
stockMate/src/main/java/com/stockm8/interceptor/AdminInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
stockMate/src/main/java/com/stockm8/interceptor/ManagerInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.stockm8.interceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.FlashMap; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
import org.springframework.web.servlet.ModelAndView; | ||
import org.springframework.web.servlet.support.RequestContextUtils; | ||
|
||
import com.stockm8.domain.enums.UserRole; | ||
import com.stockm8.domain.vo.UserVO; | ||
import com.stockm8.service.UserService; | ||
|
||
@Component | ||
public class ManagerInterceptor implements HandlerInterceptor { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ManagerInterceptor.class); | ||
|
||
@Autowired | ||
private UserService userService; // 유저 정보를 가져오기 위한 서비스 클래스 | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
HttpSession session = request.getSession(false); | ||
Long userId = (session != null) ? (Long) session.getAttribute("userId") : null; | ||
|
||
// 1. 세션에서 사용자 ID 확인 | ||
if (userId == null) { | ||
logger.warn("세션에 유저 ID가 없습니다. 로그인 페이지로 이동합니다."); | ||
saveRequestedUrlToSession(request); | ||
return sendErrorMessage(request, response, "세션이 만료되었습니다. 다시 로그인해주세요.", "/user/signin"); | ||
} | ||
|
||
// 2. DB에서 사용자 정보 조회 | ||
UserVO user = userService.getUserById(userId); | ||
if (user == null) { | ||
logger.warn("해당 유저({}) 정보를 찾을 수 없습니다. 회원가입 페이지로 이동합니다.", userId); | ||
return sendErrorMessage(request, response, "유저 정보를 찾을 수 없습니다. 회원가입을 진행해주세요.", "/user/signup"); | ||
} | ||
|
||
// 3. 삭제된 계정 확인 | ||
if (Boolean.TRUE.equals(user.getIsDeleted())) { | ||
logger.warn("삭제된 유저({})입니다. 로그인 페이지로 이동합니다.", userId); | ||
return sendErrorMessage(request, response, "삭제된 계정입니다. 관리자에게 문의해주세요.", "/user/signin"); | ||
} | ||
|
||
// 4. 관리자 권한 확인 | ||
if (user.getUserRole() != UserRole.MANAGER) { | ||
logger.warn("권한 없는 접근 시도 (유저 ID: {}, 역할: {}).", userId, user.getUserRole()); | ||
return sendErrorMessage(request, response, "매니저 전용 페이지입니다. 접근 권한이 없습니다.", "/user/signin"); | ||
} | ||
|
||
// 검증 성공: 사용자 정보 저장 | ||
logger.info("매니저 확인 완료 (유저 ID: {}, 이름: {}).", userId, user.getUserName()); | ||
request.setAttribute("currentUser", user); | ||
return true; | ||
} | ||
|
||
/** | ||
* 에러 메시지와 함께 리다이렉트 처리 | ||
*/ | ||
private boolean sendErrorMessage(HttpServletRequest request, HttpServletResponse response, String message, String redirectUrl) | ||
throws Exception { | ||
|
||
// FlashMap 객체 생성 및 에러 메시지 저장 | ||
FlashMap flashMap = new FlashMap(); | ||
flashMap.put("errorMessage", message); | ||
|
||
// FlashMap 저장소에 FlashMap 추가 | ||
RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); | ||
|
||
// 로그 출력 | ||
logger.info("FlashMap에 저장된 에러 메시지: {}", message); | ||
logger.info("리다이렉트 대상 URL: {}", redirectUrl); | ||
|
||
// 리다이렉트 수행 | ||
response.sendRedirect(redirectUrl); | ||
return false; // handlerInterceptor 처리 중단 | ||
} | ||
|
||
/** | ||
* 요청한 URL을 세션에 저장 (로그인 후 리다이렉트를 위해) | ||
*/ | ||
private void saveRequestedUrlToSession(HttpServletRequest request) { | ||
String requestedUrl = request.getRequestURI(); | ||
String queryString = request.getQueryString(); | ||
if (queryString != null) { | ||
requestedUrl += "?" + queryString; | ||
} | ||
request.getSession().setAttribute("requestedUrl", requestedUrl); | ||
} | ||
|
||
@Override | ||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, | ||
ModelAndView modelAndView) throws Exception { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) | ||
throws Exception { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.