- localStorage와 DB ID 불일치 문제 해결 - 프로젝트별 보고서 시간 필터링 수정 - 일반 사용자에게 일일공수 메뉴 숨김 - 공통 헤더 및 인증 시스템 구현 - 프로젝트별 일일공수 분리 기능 추가 (ProjectDailyWork 모델) - IssuesAPI에서 project_id 누락 문제 수정 - 사용자 인증 통합 (TokenManager 기반)
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
// 공통 인증 및 네비게이션 관리
|
|
class AuthCommon {
|
|
static init(currentPage = '') {
|
|
// 토큰 기반 사용자 정보 확인
|
|
const user = TokenManager.getUser();
|
|
if (!user) {
|
|
window.location.href = 'index.html';
|
|
return null;
|
|
}
|
|
|
|
// 전역 currentUser 설정
|
|
window.currentUser = user;
|
|
|
|
// 헤더 생성 (페이지별로 다른 active 상태)
|
|
CommonHeader.init(currentPage);
|
|
|
|
// 사용자 정보 표시
|
|
this.updateUserDisplay(user);
|
|
|
|
// 네비게이션 권한 업데이트
|
|
this.updateNavigation(user);
|
|
|
|
return user;
|
|
}
|
|
|
|
static updateUserDisplay(user) {
|
|
const userDisplayElement = document.getElementById('userDisplay');
|
|
if (userDisplayElement) {
|
|
const displayName = user.full_name || user.username;
|
|
userDisplayElement.textContent = `${displayName} (${user.username})`;
|
|
}
|
|
}
|
|
|
|
static updateNavigation(user) {
|
|
const isAdmin = user.role === 'admin';
|
|
|
|
// 관리자 전용 메뉴들
|
|
const adminMenus = [
|
|
'dailyWorkBtn',
|
|
'listBtn',
|
|
'summaryBtn',
|
|
'projectBtn',
|
|
'adminBtn'
|
|
];
|
|
|
|
adminMenus.forEach(menuId => {
|
|
const element = document.getElementById(menuId);
|
|
if (element) {
|
|
element.style.display = isAdmin ? '' : 'none';
|
|
}
|
|
});
|
|
}
|
|
|
|
static logout() {
|
|
AuthAPI.logout();
|
|
}
|
|
}
|
|
|
|
// 전역 함수들
|
|
function logout() {
|
|
AuthCommon.logout();
|
|
}
|
|
|
|
function showSection(sectionName) {
|
|
if (typeof window.showSection === 'function') {
|
|
window.showSection(sectionName);
|
|
}
|
|
}
|