feat(gateway): 통합 대시보드 네비게이션 허브 추가
로그인 후 다른 시스템으로의 진입점이 없던 문제 해결. dashboard.html에 로그인 폼 + 네비게이션 허브를 통합하고, /, /login을 /dashboard로 리다이렉트. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
613
gateway/html/dashboard.html
Normal file
613
gateway/html/dashboard.html
Normal file
@@ -0,0 +1,613 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TK 대시보드</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
background: #f0f2f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ===== Login Form ===== */
|
||||
.login-wrapper {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.login-box {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 40px;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
|
||||
}
|
||||
.login-box h1 {
|
||||
text-align: center;
|
||||
color: #1a56db;
|
||||
font-size: 22px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.login-box .sub {
|
||||
text-align: center;
|
||||
color: #6b7280;
|
||||
font-size: 13px;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.form-group { margin-bottom: 16px; }
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #374151;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
.form-group input:focus {
|
||||
border-color: #1a56db;
|
||||
box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
|
||||
}
|
||||
.btn-submit {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
background: #1a56db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.btn-submit:hover { background: #1e40af; }
|
||||
.btn-submit:disabled { background: #93c5fd; cursor: not-allowed; }
|
||||
.error-msg {
|
||||
color: #dc2626;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
margin-top: 12px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ===== Dashboard ===== */
|
||||
.header {
|
||||
background: #1a56db;
|
||||
color: white;
|
||||
padding: 14px 24px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
.header h1 { font-size: 18px; font-weight: 600; }
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.user-info span { opacity: 0.9; }
|
||||
.btn-logout {
|
||||
background: rgba(255,255,255,0.2);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 6px 14px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
.btn-logout:hover { background: rgba(255,255,255,0.3); }
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 24px 16px 40px;
|
||||
}
|
||||
.section { margin-bottom: 28px; }
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #374151;
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
/* Card grid */
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 10px;
|
||||
}
|
||||
@media (min-width: 640px) {
|
||||
.card-grid { grid-template-columns: repeat(3, 1fr); }
|
||||
}
|
||||
@media (min-width: 1024px) {
|
||||
.card-grid { grid-template-columns: repeat(4, 1fr); }
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
padding: 14px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 56px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
|
||||
transition: transform 0.15s, box-shadow 0.15s;
|
||||
cursor: pointer;
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
.card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
||||
}
|
||||
.card:active { transform: translateY(0); }
|
||||
.card-icon { font-size: 22px; flex-shrink: 0; }
|
||||
.card-name { font-size: 13px; font-weight: 500; color: #1f2937; line-height: 1.3; }
|
||||
|
||||
/* System cards */
|
||||
.system-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 10px;
|
||||
}
|
||||
@media (min-width: 640px) {
|
||||
.system-grid { grid-template-columns: repeat(3, 1fr); }
|
||||
}
|
||||
.system-card {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
padding: 18px 16px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
|
||||
transition: transform 0.15s, box-shadow 0.15s;
|
||||
cursor: pointer;
|
||||
border-left: 4px solid;
|
||||
}
|
||||
.system-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
||||
}
|
||||
.system-card .card-icon { font-size: 26px; }
|
||||
.system-card .card-name { font-size: 14px; font-weight: 600; }
|
||||
|
||||
/* Coming soon */
|
||||
.badge-soon {
|
||||
display: inline-block;
|
||||
background: #f3f4f6;
|
||||
color: #6b7280;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
margin-left: 4px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.card.coming-soon {
|
||||
opacity: 0.55;
|
||||
cursor: default;
|
||||
}
|
||||
.card.coming-soon:hover {
|
||||
transform: none;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: 16px;
|
||||
color: #9ca3af;
|
||||
font-size: 11px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Login Form -->
|
||||
<div id="loginView" class="login-wrapper" style="display:none">
|
||||
<div class="login-box">
|
||||
<h1>TK 공장관리 시스템</h1>
|
||||
<p class="sub">통합 로그인</p>
|
||||
<form id="loginForm" onsubmit="handleLogin(event)">
|
||||
<div class="form-group">
|
||||
<label for="username">사용자명</label>
|
||||
<input type="text" id="username" name="username" required autofocus autocomplete="username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">비밀번호</label>
|
||||
<input type="password" id="password" name="password" required autocomplete="current-password">
|
||||
</div>
|
||||
<button type="submit" class="btn-submit" id="submitBtn">로그인</button>
|
||||
<p class="error-msg" id="errorMsg"></p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Dashboard -->
|
||||
<div id="dashboardView" style="display:none">
|
||||
<div class="header">
|
||||
<h1>TK 대시보드</h1>
|
||||
<div class="user-info">
|
||||
<span id="userName"></span>
|
||||
<button class="btn-logout" onclick="logout()">로그아웃</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="section" id="frequentSection" style="display:none">
|
||||
<div class="section-title"><span>⭐</span> 자주 사용</div>
|
||||
<div class="card-grid" id="frequentGrid"></div>
|
||||
</div>
|
||||
<div class="section" id="dailySection" style="display:none">
|
||||
<div class="section-title"><span>📌</span> 일상 업무</div>
|
||||
<div class="card-grid" id="dailyGrid"></div>
|
||||
</div>
|
||||
<div class="section" id="systemSection" style="display:none">
|
||||
<div class="section-title"><span>🏢</span> 시스템</div>
|
||||
<div class="system-grid" id="systemGrid"></div>
|
||||
</div>
|
||||
<div class="section" id="toolSection" style="display:none">
|
||||
<div class="section-title"><span>🔧</span> 업무 도구</div>
|
||||
<div class="card-grid" id="toolGrid"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">TK Factory Services v1.0</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ===== SSO Cookie Utility =====
|
||||
var ssoCookie = {
|
||||
set: function(name, value, days) {
|
||||
var cookie = name + '=' + encodeURIComponent(value) + '; path=/';
|
||||
if (days) cookie += '; max-age=' + (days * 86400);
|
||||
if (window.location.hostname.includes('technicalkorea.net')) {
|
||||
cookie += '; domain=.technicalkorea.net; secure; samesite=lax';
|
||||
}
|
||||
document.cookie = cookie;
|
||||
},
|
||||
get: function(name) {
|
||||
var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
},
|
||||
remove: function(name) {
|
||||
var cookie = name + '=; path=/; max-age=0';
|
||||
if (window.location.hostname.includes('technicalkorea.net')) {
|
||||
cookie += '; domain=.technicalkorea.net; secure; samesite=lax';
|
||||
}
|
||||
document.cookie = cookie;
|
||||
}
|
||||
};
|
||||
|
||||
function getToken() {
|
||||
return ssoCookie.get('sso_token') || localStorage.getItem('sso_token');
|
||||
}
|
||||
function getUser() {
|
||||
var raw = ssoCookie.get('sso_user') || localStorage.getItem('sso_user');
|
||||
try { return JSON.parse(raw); } catch(e) { return null; }
|
||||
}
|
||||
function isTokenValid(token) {
|
||||
try {
|
||||
var payload = JSON.parse(atob(token.split('.')[1]));
|
||||
return payload.exp > Math.floor(Date.now() / 1000);
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
function isSafeRedirect(url) {
|
||||
if (!url) return false;
|
||||
if (/^\/[a-zA-Z0-9]/.test(url) && !url.includes('://') && !url.includes('//')) return true;
|
||||
try {
|
||||
var parsed = new URL(url);
|
||||
return parsed.hostname.endsWith('.technicalkorea.net') || parsed.hostname === 'technicalkorea.net';
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
|
||||
// ===== Subdomain URLs =====
|
||||
function getSubdomainUrl(name) {
|
||||
var hostname = window.location.hostname;
|
||||
var protocol = window.location.protocol;
|
||||
if (hostname.includes('technicalkorea.net')) {
|
||||
return protocol + '//' + name + '.technicalkorea.net';
|
||||
}
|
||||
var ports = { tkreport: 30180, tkqc: 30280, tkuser: 30380, tkpurchase: 30480, tksafety: 30580, tksupport: 30680 };
|
||||
return protocol + '//' + hostname + ':' + (ports[name] || 30000);
|
||||
}
|
||||
|
||||
// ===== Card Definitions =====
|
||||
var DAILY_CARDS = [
|
||||
{ id: 'tbm', name: 'TBM', icon: '\uD83D\uDCCB', href: '/pages/work/tbm.html', pageKey: 's1.work.tbm' },
|
||||
{ id: 'report', name: '\uC791\uC5C5\uBCF4\uACE0\uC11C', icon: '\uD83D\uDCDD', href: '/pages/work/report-create.html', pageKey: 's1.work.report_create' },
|
||||
{ id: 'issue', name: '\uC548\uC804\uC2E0\uACE0', icon: '\u26A0\uFE0F', subdomain: 'tkreport', path: '/pages/safety/issue-report.html', accessKey: 'system2' },
|
||||
{ id: 'checkin', name: '\uCD9C\uD1F4\uADFC \uCCB4\uD06C', icon: '\u23F0', href: '/pages/attendance/checkin.html', pageKey: 's1.inspection.checkin' },
|
||||
{ id: 'vacation', name: '\uB0B4 \uC5F0\uCC28 \uC815\uBCF4', icon: '\uD83C\uDFD6\uFE0F', href: '/pages/attendance/my-vacation-info.html', pageKey: 's1.attendance.my_vacation_info' },
|
||||
{ id: 'leave', name: '\uD734\uAC00 \uC2E0\uCCAD', icon: '\uD83D\uDCC5', href: '/pages/attendance/vacation-request.html', pageKey: 's1.attendance.vacation_request' }
|
||||
];
|
||||
|
||||
var SYSTEM_CARDS = [
|
||||
{ id: 'factory', name: '\uACF5\uC7A5\uAD00\uB9AC', icon: '\uD83C\uDFED', href: '/pages/dashboard.html', pageKey: 's1.dashboard', color: '#1a56db' },
|
||||
{ id: 'report_sys', name: '\uC2E0\uACE0', icon: '\uD83D\uDEA8', subdomain: 'tkreport', accessKey: 'system2', color: '#dc2626' },
|
||||
{ id: 'quality', name: '\uBD80\uC801\uD569\uAD00\uB9AC', icon: '\uD83D\uDCCA', subdomain: 'tkqc', pageKey: 'issues_dashboard', color: '#059669' }
|
||||
];
|
||||
|
||||
var TOOL_CARDS = [
|
||||
{ id: 'purchase', name: '\uAD6C\uB9E4\uAD00\uB9AC', icon: '\uD83D\uDED2', subdomain: 'tkpurchase', pageKey: 'purchasing_schedule' },
|
||||
{ id: 'safety', name: '\uC548\uC804\uAD00\uB9AC', icon: '\uD83D\uDD27', subdomain: 'tksafety', pageKey: 'safety_visit_management' },
|
||||
{ id: 'support', name: '\uD589\uC815\uC9C0\uC6D0', icon: '\uD83C\uDFE2', comingSoon: true },
|
||||
{ id: 'admin', name: '\uD1B5\uD569\uAD00\uB9AC', icon: '\u2699\uFE0F', subdomain: 'tkuser', pageKey: 'tkuser.users' }
|
||||
];
|
||||
|
||||
// ===== Click Tracking =====
|
||||
function trackClick(linkId) {
|
||||
var clicks = JSON.parse(localStorage.getItem('hub_clicks') || '{}');
|
||||
clicks[linkId] = (clicks[linkId] || 0) + 1;
|
||||
localStorage.setItem('hub_clicks', JSON.stringify(clicks));
|
||||
}
|
||||
|
||||
function getFrequentIds(limit) {
|
||||
var clicks = JSON.parse(localStorage.getItem('hub_clicks') || '{}');
|
||||
if (Object.keys(clicks).length === 0) {
|
||||
return ['tbm', 'report', 'checkin', 'vacation'];
|
||||
}
|
||||
return Object.entries(clicks)
|
||||
.sort(function(a, b) { return b[1] - a[1]; })
|
||||
.slice(0, limit)
|
||||
.map(function(e) { return e[0]; });
|
||||
}
|
||||
|
||||
// ===== Rendering =====
|
||||
function resolveHref(card) {
|
||||
if (card.href) return card.href;
|
||||
if (card.subdomain) {
|
||||
var base = getSubdomainUrl(card.subdomain);
|
||||
return card.path ? base + card.path : base;
|
||||
}
|
||||
return '#';
|
||||
}
|
||||
|
||||
function createCardElement(card, isSystem) {
|
||||
var a = document.createElement('a');
|
||||
a.className = isSystem ? 'system-card' : 'card';
|
||||
|
||||
if (isSystem && card.color) {
|
||||
a.style.borderLeftColor = card.color;
|
||||
}
|
||||
|
||||
if (card.comingSoon) {
|
||||
a.className += ' coming-soon';
|
||||
a.href = 'javascript:void(0)';
|
||||
a.onclick = function(e) { e.preventDefault(); };
|
||||
} else {
|
||||
a.href = resolveHref(card);
|
||||
a.onclick = function() { trackClick(card.id); };
|
||||
}
|
||||
|
||||
var iconSpan = document.createElement('span');
|
||||
iconSpan.className = 'card-icon';
|
||||
iconSpan.textContent = card.icon;
|
||||
a.appendChild(iconSpan);
|
||||
|
||||
var nameSpan = document.createElement('span');
|
||||
nameSpan.className = 'card-name';
|
||||
nameSpan.textContent = card.name;
|
||||
|
||||
if (card.comingSoon) {
|
||||
var badge = document.createElement('span');
|
||||
badge.className = 'badge-soon';
|
||||
badge.textContent = '\uC900\uBE44\uC911';
|
||||
nameSpan.appendChild(document.createTextNode(' '));
|
||||
nameSpan.appendChild(badge);
|
||||
}
|
||||
|
||||
a.appendChild(nameSpan);
|
||||
return a;
|
||||
}
|
||||
|
||||
function isCardVisible(card, allowed, systemAccess) {
|
||||
if (card.comingSoon) return true;
|
||||
if (card.pageKey && !allowed.has(card.pageKey)) return false;
|
||||
if (card.accessKey && systemAccess[card.accessKey] === false) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function renderSection(sectionId, gridId, cards, allowed, systemAccess, isSystem) {
|
||||
var visible = cards.filter(function(c) { return isCardVisible(c, allowed, systemAccess); });
|
||||
if (visible.length === 0) return;
|
||||
|
||||
var grid = document.getElementById(gridId);
|
||||
grid.innerHTML = '';
|
||||
visible.forEach(function(card) {
|
||||
grid.appendChild(createCardElement(card, isSystem));
|
||||
});
|
||||
document.getElementById(sectionId).style.display = '';
|
||||
}
|
||||
|
||||
// ===== Dashboard =====
|
||||
async function showDashboard(user, token) {
|
||||
document.getElementById('loginView').style.display = 'none';
|
||||
document.getElementById('dashboardView').style.display = '';
|
||||
document.getElementById('userName').textContent = (user.name || user.username);
|
||||
|
||||
var systemAccess = user.system_access || {};
|
||||
var allowed = new Set();
|
||||
|
||||
// Fetch page access
|
||||
try {
|
||||
var userId = user.user_id || user.id;
|
||||
var res = await fetch('/api/users/' + userId + '/page-access', {
|
||||
headers: { 'Authorization': 'Bearer ' + token }
|
||||
});
|
||||
var data = await res.json();
|
||||
if (data.success && data.data && data.data.pageAccess) {
|
||||
data.data.pageAccess.forEach(function(p) {
|
||||
if (p.can_access) allowed.add(p.page_key);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Fallback: show cards based on system_access
|
||||
console.warn('page-access API error:', e);
|
||||
if (systemAccess.system1 !== false) {
|
||||
['s1.work.tbm', 's1.work.report_create', 's1.inspection.checkin',
|
||||
's1.attendance.my_vacation_info', 's1.attendance.vacation_request',
|
||||
's1.dashboard'].forEach(function(k) { allowed.add(k); });
|
||||
}
|
||||
if (systemAccess.system3 !== false) allowed.add('issues_dashboard');
|
||||
}
|
||||
|
||||
// Render main sections
|
||||
renderSection('dailySection', 'dailyGrid', DAILY_CARDS, allowed, systemAccess, false);
|
||||
renderSection('systemSection', 'systemGrid', SYSTEM_CARDS, allowed, systemAccess, true);
|
||||
renderSection('toolSection', 'toolGrid', TOOL_CARDS, allowed, systemAccess, false);
|
||||
|
||||
// Frequent section
|
||||
var allCards = DAILY_CARDS.concat(TOOL_CARDS);
|
||||
var cardMap = {};
|
||||
allCards.forEach(function(c) { cardMap[c.id] = c; });
|
||||
|
||||
var frequentIds = getFrequentIds(4);
|
||||
var frequentCards = frequentIds
|
||||
.map(function(id) { return cardMap[id]; })
|
||||
.filter(function(c) { return c && !c.comingSoon && isCardVisible(c, allowed, systemAccess); });
|
||||
|
||||
if (frequentCards.length > 0) {
|
||||
var grid = document.getElementById('frequentGrid');
|
||||
grid.innerHTML = '';
|
||||
frequentCards.forEach(function(card) {
|
||||
grid.appendChild(createCardElement(card, false));
|
||||
});
|
||||
document.getElementById('frequentSection').style.display = '';
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Login =====
|
||||
async function handleLogin(e) {
|
||||
e.preventDefault();
|
||||
var btn = document.getElementById('submitBtn');
|
||||
var errEl = document.getElementById('errorMsg');
|
||||
errEl.style.display = 'none';
|
||||
btn.disabled = true;
|
||||
btn.textContent = '\uB85C\uADF8\uC778 \uC911...';
|
||||
|
||||
try {
|
||||
var res = await fetch('/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: document.getElementById('username').value,
|
||||
password: document.getElementById('password').value
|
||||
})
|
||||
});
|
||||
var data = await res.json();
|
||||
if (!res.ok || !data.success) throw new Error(data.error || '\uB85C\uADF8\uC778\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4');
|
||||
|
||||
ssoCookie.set('sso_token', data.access_token, 7);
|
||||
ssoCookie.set('sso_user', JSON.stringify(data.user), 7);
|
||||
if (data.refresh_token) ssoCookie.set('sso_refresh_token', data.refresh_token, 30);
|
||||
|
||||
localStorage.setItem('sso_token', data.access_token);
|
||||
localStorage.setItem('sso_user', JSON.stringify(data.user));
|
||||
if (data.refresh_token) localStorage.setItem('sso_refresh_token', data.refresh_token);
|
||||
|
||||
var redirect = new URLSearchParams(location.search).get('redirect');
|
||||
if (redirect && isSafeRedirect(redirect)) {
|
||||
window.location.href = redirect;
|
||||
} else {
|
||||
window.location.href = '/dashboard';
|
||||
}
|
||||
} catch (err) {
|
||||
errEl.textContent = err.message;
|
||||
errEl.style.display = '';
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '\uB85C\uADF8\uC778';
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Logout =====
|
||||
function logout() {
|
||||
ssoCookie.remove('sso_token');
|
||||
ssoCookie.remove('sso_user');
|
||||
ssoCookie.remove('sso_refresh_token');
|
||||
['sso_token','sso_user','sso_refresh_token','token','user','access_token',
|
||||
'currentUser','current_user','userInfo','userPageAccess'].forEach(function(k) {
|
||||
localStorage.removeItem(k);
|
||||
});
|
||||
fetch('/auth/logout', { method: 'POST' }).catch(function(){});
|
||||
window.location.href = '/dashboard?logout=1';
|
||||
}
|
||||
|
||||
// ===== Auth cleanup helpers =====
|
||||
function clearAllAuth() {
|
||||
ssoCookie.remove('sso_token');
|
||||
ssoCookie.remove('sso_user');
|
||||
ssoCookie.remove('sso_refresh_token');
|
||||
['sso_token','sso_user','sso_refresh_token','token','user','access_token',
|
||||
'currentUser','current_user','userInfo','userPageAccess'].forEach(function(k) {
|
||||
localStorage.removeItem(k);
|
||||
});
|
||||
}
|
||||
|
||||
// ===== Entry Point =====
|
||||
(function init() {
|
||||
var params = new URLSearchParams(location.search);
|
||||
var isLogout = params.get('logout') === '1';
|
||||
|
||||
if (isLogout) clearAllAuth();
|
||||
|
||||
var token = isLogout ? null : getToken();
|
||||
|
||||
if (token && token !== 'undefined' && token !== 'null') {
|
||||
if (isTokenValid(token)) {
|
||||
var user = getUser();
|
||||
if (user) {
|
||||
// Partner redirect
|
||||
if (user.partner_company_id) {
|
||||
window.location.href = '/pages/partner/partner-portal.html';
|
||||
return;
|
||||
}
|
||||
|
||||
// Already logged in + redirect param
|
||||
var redirect = params.get('redirect');
|
||||
if (redirect && isSafeRedirect(redirect)) {
|
||||
window.location.href = redirect;
|
||||
return;
|
||||
}
|
||||
|
||||
// Sync cookies
|
||||
var existingUser = ssoCookie.get('sso_user') || localStorage.getItem('sso_user');
|
||||
var existingRefresh = ssoCookie.get('sso_refresh_token') || localStorage.getItem('sso_refresh_token');
|
||||
ssoCookie.set('sso_token', token, 7);
|
||||
if (existingUser) ssoCookie.set('sso_user', existingUser, 7);
|
||||
if (existingRefresh) ssoCookie.set('sso_refresh_token', existingRefresh, 30);
|
||||
|
||||
showDashboard(user, token);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Token invalid or no user data
|
||||
clearAllAuth();
|
||||
}
|
||||
|
||||
// Show login
|
||||
document.getElementById('loginView').style.display = 'flex';
|
||||
document.getElementById('dashboardView').style.display = 'none';
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -62,10 +62,10 @@
|
||||
var loginUrl;
|
||||
|
||||
if (hostname.includes('technicalkorea.net')) {
|
||||
loginUrl = window.location.protocol + '//tkfb.technicalkorea.net/login';
|
||||
loginUrl = window.location.protocol + '//tkfb.technicalkorea.net/dashboard';
|
||||
} else {
|
||||
// 개발 환경: Gateway 포트 (30000)
|
||||
loginUrl = window.location.protocol + '//' + hostname + ':30000/login';
|
||||
loginUrl = window.location.protocol + '//' + hostname + ':30000/dashboard';
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
|
||||
@@ -7,11 +7,21 @@ server {
|
||||
# ===== Gateway 자체 페이지 (포털, 로그인) =====
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
# 로그인 페이지 (캐시 금지 — SSO 쿠키 재설정 로직 항상 최신 반영)
|
||||
location = /login {
|
||||
# 대시보드 (로그인 + 네비게이션 허브 통합)
|
||||
location = /dashboard {
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
try_files /login.html =404;
|
||||
try_files /dashboard.html =404;
|
||||
}
|
||||
|
||||
# 루트 → 대시보드 리다이렉트
|
||||
location = / {
|
||||
return 302 /dashboard$is_args$args;
|
||||
}
|
||||
|
||||
# 로그인 → 대시보드 리다이렉트
|
||||
location = /login {
|
||||
return 302 /dashboard$is_args$args;
|
||||
}
|
||||
|
||||
# 공유 JS/CSS (nav-header 등)
|
||||
|
||||
Reference in New Issue
Block a user