-
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.
Update admin/ Update register.jsp(css 보류)
- Loading branch information
Showing
26 changed files
with
932 additions
and
413 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
stockMate/src/main/java/com/stockm8/config/ApplicationContextProvider.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,20 @@ | ||
package com.stockm8.config; | ||
|
||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ApplicationContextProvider implements ApplicationContextAware { | ||
|
||
private static ApplicationContext context; | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) { | ||
context = applicationContext; | ||
} | ||
|
||
public static <T> T getBean(Class<T> requiredType) { | ||
return context.getBean(requiredType); | ||
} | ||
} |
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
116 changes: 62 additions & 54 deletions
116
stockMate/src/main/java/com/stockm8/controller/AdminController.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,80 +1,88 @@ | ||
package com.stockm8.controller; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
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.http.MediaType; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import com.stockm8.domain.vo.Criteria; | ||
import com.stockm8.domain.vo.OrderItemVO; | ||
import com.stockm8.domain.vo.OrderVO; | ||
import com.stockm8.domain.vo.PageVO; | ||
import com.stockm8.domain.vo.OrderVO.OrderType; | ||
import com.stockm8.domain.vo.StockVO; | ||
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.OrderService; | ||
import com.stockm8.service.UserService; | ||
|
||
@Controller | ||
@RequestMapping(value = "/admin/*") | ||
public class AdminController { | ||
|
||
// 현재 로그인한 사용자 정보 가져오기(인터셉터에서 정의됨) | ||
private UserVO getCurrentUser(HttpServletRequest request) { | ||
return (UserVO) request.getAttribute("currentUser"); | ||
} | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AdminController.class); | ||
|
||
@Inject | ||
private OrderService orderService; | ||
@Inject | ||
private UserService userService; | ||
|
||
/** | ||
* 어드민 메인 페이지 표시(GET) | ||
* http://localhost:8088/admin/adminMain | ||
* | ||
*/ | ||
@RequestMapping(value = "/adminMain", method = RequestMethod.GET) | ||
public String adminMainGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
logger.info("adminMainGET() 호출"); | ||
|
||
UserVO currentUser = getCurrentUser(request); | ||
int businessId = currentUser.getBusinessId(); | ||
|
||
return "admin/adminMain"; | ||
} | ||
/** | ||
* 어드민 회원목록표시(GET) | ||
* http://localhost:8088/admin/adminList | ||
* | ||
*/ | ||
@RequestMapping(value = "/adminList", method = RequestMethod.GET) | ||
public String adminListGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
logger.info("adminListGET() 호출"); | ||
|
||
UserVO currentUser = getCurrentUser(request); | ||
int businessId = currentUser.getBusinessId(); | ||
|
||
return "admin/adminList"; | ||
return (UserVO) request.getAttribute("currentUser"); | ||
} | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AdminController.class); | ||
|
||
@Inject | ||
private OrderService orderService; | ||
@Inject | ||
private UserService userService; | ||
|
||
/** | ||
* 관리자 메인 페이지 표시(GET) http://localhost:8088/admin/main | ||
* | ||
* @throws Exception | ||
* | ||
*/ | ||
@GetMapping("/main") | ||
public String adminMainGET(@SessionAttribute("userId") Long userId, Model model) throws Exception { | ||
logger.info("adminMainGET() 호출 - 페이지 접근 (userId: {})", userId); | ||
|
||
// userId로 사용자 정보 가져오기 | ||
UserVO user = userService.getUserById(userId); | ||
|
||
if (user != null) { | ||
// 관리자 여부 확인 (ADMIN인 경우) | ||
boolean isAdmin = user.getUserRole() == UserRole.ADMIN; | ||
model.addAttribute("isAdmin", isAdmin); // JSP에 전달할 데이터 | ||
} | ||
return "admin/main"; // 메인 페이지 반환 | ||
} | ||
|
||
@GetMapping("/approve") | ||
public String adminApproveGET(@SessionAttribute("userId") Long userId, Model model) throws Exception { | ||
logger.info("adminApproveGET() 호출 - 페이지 접근 (userId: {})", userId); | ||
|
||
// 조건에 맞는 사용자와 사업자 정보 가져오기 | ||
List<PendingUserDTO> pendingUsers = userService.getPendingUsersWithBusiness(); | ||
|
||
// JSP로 전달 | ||
model.addAttribute("pendingUsers", pendingUsers); | ||
|
||
return "admin/main"; // JSP 페이지 반환 | ||
} | ||
|
||
/** | ||
* 관리자 회원목록표시(GET) http://localhost:8088/admin/userList | ||
* | ||
*/ | ||
@RequestMapping(value = "/adminList", method = RequestMethod.GET) | ||
public String adminListGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
logger.info("adminListGET() 호출"); | ||
|
||
UserVO currentUser = getCurrentUser(request); | ||
int businessId = currentUser.getBusinessId(); | ||
|
||
return "admin/userList"; | ||
} | ||
|
||
|
||
} //AdminController | ||
} // AdminController |
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
23 changes: 23 additions & 0 deletions
23
stockMate/src/main/java/com/stockm8/domain/dto/PendingUserDTO.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,23 @@ | ||
package com.stockm8.domain.dto; | ||
|
||
import java.sql.Timestamp; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class PendingUserDTO { | ||
|
||
// 사용자 정보 | ||
private Long userId; | ||
private String email; | ||
private String userName; | ||
private String userRole; | ||
private String telNumber; | ||
private Timestamp createdAt; | ||
|
||
// 사업자 정보 | ||
private Integer businessId; | ||
private String businessNumber; | ||
private String businessName; | ||
|
||
} |
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
100 changes: 100 additions & 0 deletions
100
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.stockm8.interceptor; | ||
|
||
import java.io.IOException; | ||
|
||
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.HandlerInterceptor; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import com.stockm8.domain.enums.UserRole; | ||
import com.stockm8.domain.vo.UserVO; | ||
import com.stockm8.service.UserService; | ||
|
||
@Component | ||
public class AdminInterceptor implements HandlerInterceptor { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AdminInterceptor.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.ADMIN) { | ||
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 IOException { | ||
request.getSession().setAttribute("errorMessage", message); | ||
response.sendRedirect(request.getContextPath() + redirectUrl); | ||
return false; // 요청 중단 | ||
} | ||
|
||
/** | ||
* 요청한 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
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.