443 lines
14 KiB
HTML
443 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ko">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>SmallClaw — Login</title>
|
|
<style>
|
|
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');
|
|
|
|
:root {
|
|
--bg: #f4f6fb;
|
|
--bg-soft: #eef2f8;
|
|
--panel: #ffffff;
|
|
--panel-2: #f8fafc;
|
|
--line: #dbe3ee;
|
|
--line-strong: #c7d3e3;
|
|
--text: #0f172a;
|
|
--muted: #5f6f86;
|
|
--brand: #1668e3;
|
|
--brand-2: #0f4fba;
|
|
--ok: #0f9f6e;
|
|
--warn: #d18b19;
|
|
--err: #d14b4b;
|
|
--radius-sm: 10px;
|
|
--radius-md: 14px;
|
|
--radius-lg: 18px;
|
|
--shadow-sm: 0 2px 6px rgba(16, 32, 64, 0.06);
|
|
--shadow-md: 0 8px 24px rgba(16, 32, 64, 0.08);
|
|
}
|
|
|
|
:root[data-theme="dark"] {
|
|
--bg: #1f242d;
|
|
--bg-soft: #242a34;
|
|
--panel: #2a313d;
|
|
--panel-2: #323a47;
|
|
--line: #3d4656;
|
|
--line-strong: #505b70;
|
|
--text: #e8edf6;
|
|
--muted: #aeb9cb;
|
|
--brand: #4c8dff;
|
|
--brand-2: #2f6fe0;
|
|
--ok: #31b884;
|
|
--warn: #d6a64f;
|
|
--err: #e06d6d;
|
|
--shadow-sm: 0 2px 8px rgba(4, 7, 12, 0.28);
|
|
--shadow-md: 0 10px 30px rgba(4, 7, 12, 0.36);
|
|
}
|
|
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
min-height: 100vh;
|
|
font-family: 'Manrope', sans-serif;
|
|
color: var(--text);
|
|
background:
|
|
radial-gradient(900px 420px at 8% -15%, rgba(22, 104, 227, 0.12), transparent 65%),
|
|
radial-gradient(900px 420px at 100% -20%, rgba(33, 166, 255, 0.12), transparent 62%),
|
|
var(--bg);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 20px;
|
|
}
|
|
:root[data-theme="dark"] body {
|
|
background:
|
|
radial-gradient(900px 420px at 8% -15%, rgba(76, 141, 255, 0.12), transparent 65%),
|
|
radial-gradient(900px 420px at 100% -20%, rgba(89, 188, 255, 0.1), transparent 62%),
|
|
var(--bg);
|
|
}
|
|
|
|
.login-card {
|
|
width: 100%;
|
|
max-width: 400px;
|
|
background: var(--panel);
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius-lg);
|
|
box-shadow: var(--shadow-md);
|
|
padding: 40px 32px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 24px;
|
|
}
|
|
|
|
.logo-area {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.logo-icon {
|
|
width: 40px;
|
|
height: 40px;
|
|
background: linear-gradient(135deg, var(--brand), var(--brand-2));
|
|
border-radius: 12px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: #fff;
|
|
font-weight: 800;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.logo-text {
|
|
font-size: 24px;
|
|
font-weight: 800;
|
|
letter-spacing: -0.5px;
|
|
}
|
|
|
|
.subtitle {
|
|
font-size: 14px;
|
|
color: var(--muted);
|
|
text-align: center;
|
|
}
|
|
|
|
.form-group {
|
|
width: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 6px;
|
|
}
|
|
|
|
.form-label {
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.form-input {
|
|
width: 100%;
|
|
padding: 12px 14px;
|
|
font-family: 'IBM Plex Mono', monospace;
|
|
font-size: 14px;
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius-sm);
|
|
background: var(--panel-2);
|
|
color: var(--text);
|
|
outline: none;
|
|
transition: border-color 0.2s, box-shadow 0.2s;
|
|
}
|
|
.form-input:focus {
|
|
border-color: var(--brand);
|
|
box-shadow: 0 0 0 3px rgba(22, 104, 227, 0.15);
|
|
}
|
|
:root[data-theme="dark"] .form-input:focus {
|
|
box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.2);
|
|
}
|
|
|
|
.btn {
|
|
width: 100%;
|
|
padding: 12px 20px;
|
|
font-family: 'Manrope', sans-serif;
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
border: none;
|
|
border-radius: var(--radius-sm);
|
|
cursor: pointer;
|
|
transition: background 0.2s, transform 0.1s;
|
|
}
|
|
.btn:active { transform: scale(0.98); }
|
|
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, var(--brand), var(--brand-2));
|
|
color: #fff;
|
|
}
|
|
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
|
|
|
|
.error-msg {
|
|
width: 100%;
|
|
padding: 10px 14px;
|
|
background: rgba(209, 75, 75, 0.1);
|
|
border: 1px solid rgba(209, 75, 75, 0.3);
|
|
border-radius: var(--radius-sm);
|
|
color: var(--err);
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
display: none;
|
|
}
|
|
.error-msg.visible { display: block; }
|
|
|
|
.theme-toggle {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 20px;
|
|
width: 36px;
|
|
height: 36px;
|
|
background: var(--panel);
|
|
border: 1px solid var(--line);
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
color: var(--muted);
|
|
transition: background 0.2s;
|
|
}
|
|
.theme-toggle:hover { background: var(--panel-2); }
|
|
|
|
.password-wrapper {
|
|
position: relative;
|
|
width: 100%;
|
|
}
|
|
|
|
.toggle-pw {
|
|
position: absolute;
|
|
right: 12px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
background: none;
|
|
border: none;
|
|
color: var(--muted);
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
padding: 4px;
|
|
line-height: 1;
|
|
}
|
|
|
|
.migrate-notice {
|
|
width: 100%;
|
|
padding: 10px 14px;
|
|
background: rgba(209, 143, 25, 0.1);
|
|
border: 1px solid rgba(209, 143, 25, 0.3);
|
|
border-radius: var(--radius-sm);
|
|
color: var(--warn);
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
display: none;
|
|
}
|
|
.migrate-notice.visible { display: block; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<button class="theme-toggle" id="themeToggle" title="Toggle theme">☾</button>
|
|
|
|
<div class="login-card">
|
|
<div class="logo-area">
|
|
<div class="logo-icon">SC</div>
|
|
<div class="logo-text">SmallClaw</div>
|
|
</div>
|
|
<p class="subtitle" id="subtitle">인증 확인 중...</p>
|
|
|
|
<div class="migrate-notice" id="migrateNotice">
|
|
계정에 사용자 이름이 필요합니다. 업그레이드할 이름을 선택하세요.
|
|
</div>
|
|
|
|
<form id="authForm" style="display:none; width:100%; display:flex; flex-direction:column; gap:16px;">
|
|
<div class="form-group" id="usernameGroup" style="display:none;">
|
|
<label class="form-label" id="usernameLabel">사용자 이름</label>
|
|
<input type="text" class="form-input" id="username" autocomplete="username" placeholder="사용자 이름 입력">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label" id="pwLabel">비밀번호</label>
|
|
<div class="password-wrapper">
|
|
<input type="password" class="form-input" id="password" autocomplete="current-password" placeholder="비밀번호 입력" style="padding-right:40px;">
|
|
<button type="button" class="toggle-pw" id="togglePw" title="Show password">👁</button>
|
|
</div>
|
|
</div>
|
|
<div class="form-group" id="confirmGroup" style="display:none;">
|
|
<label class="form-label">비밀번호 확인</label>
|
|
<input type="password" class="form-input" id="confirmPassword" autocomplete="new-password" placeholder="비밀번호 확인 입력">
|
|
</div>
|
|
<div class="error-msg" id="errorMsg"></div>
|
|
<button type="submit" class="btn btn-primary" id="submitBtn">로그인</button>
|
|
</form>
|
|
</div>
|
|
|
|
<script>
|
|
(function() {
|
|
const form = document.getElementById('authForm');
|
|
const subtitle = document.getElementById('subtitle');
|
|
const usernameInput = document.getElementById('username');
|
|
const usernameGroup = document.getElementById('usernameGroup');
|
|
const usernameLabel = document.getElementById('usernameLabel');
|
|
const passwordInput = document.getElementById('password');
|
|
const confirmInput = document.getElementById('confirmPassword');
|
|
const confirmGroup = document.getElementById('confirmGroup');
|
|
const pwLabel = document.getElementById('pwLabel');
|
|
const errorMsg = document.getElementById('errorMsg');
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
const togglePw = document.getElementById('togglePw');
|
|
const themeToggle = document.getElementById('themeToggle');
|
|
const migrateNotice = document.getElementById('migrateNotice');
|
|
|
|
let mode = 'login'; // 'setup' | 'login' | 'legacy-migrate'
|
|
|
|
// Theme
|
|
const savedTheme = localStorage.getItem('sc-theme') || 'light';
|
|
document.documentElement.setAttribute('data-theme', savedTheme);
|
|
themeToggle.textContent = savedTheme === 'dark' ? '☀' : '☾';
|
|
themeToggle.addEventListener('click', () => {
|
|
const current = document.documentElement.getAttribute('data-theme');
|
|
const next = current === 'dark' ? 'light' : 'dark';
|
|
document.documentElement.setAttribute('data-theme', next);
|
|
localStorage.setItem('sc-theme', next);
|
|
themeToggle.textContent = next === 'dark' ? '☀' : '☾';
|
|
});
|
|
|
|
// Toggle password visibility
|
|
togglePw.addEventListener('click', () => {
|
|
const isPassword = passwordInput.type === 'password';
|
|
passwordInput.type = isPassword ? 'text' : 'password';
|
|
togglePw.textContent = isPassword ? '✎' : '👁';
|
|
});
|
|
|
|
function showError(msg) {
|
|
errorMsg.textContent = msg;
|
|
errorMsg.classList.add('visible');
|
|
}
|
|
function hideError() {
|
|
errorMsg.classList.remove('visible');
|
|
}
|
|
|
|
async function checkStatus() {
|
|
try {
|
|
const res = await fetch('/api/auth/status');
|
|
const data = await res.json();
|
|
|
|
if (!data.enabled) {
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
if (data.authenticated) {
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
if (data.hasLegacyPassword && !data.hasUsers) {
|
|
// Legacy mode: old password-only install needs migration
|
|
mode = 'legacy-migrate';
|
|
subtitle.textContent = '업그레이드할 사용자 이름을 설정하세요';
|
|
migrateNotice.classList.add('visible');
|
|
usernameGroup.style.display = 'flex';
|
|
usernameLabel.textContent = '사용자 이름';
|
|
usernameInput.placeholder = '사용자 이름 선택';
|
|
pwLabel.textContent = '현재 비밀번호';
|
|
submitBtn.textContent = '업그레이드 & 로그인';
|
|
confirmGroup.style.display = 'none';
|
|
passwordInput.autocomplete = 'current-password';
|
|
passwordInput.placeholder = '현재 비밀번호를 입력하세요';
|
|
} else if (!data.hasUsers) {
|
|
// Fresh install: first user setup
|
|
mode = 'setup';
|
|
subtitle.textContent = '관리자 계정 생성';
|
|
migrateNotice.classList.remove('visible');
|
|
usernameGroup.style.display = 'flex';
|
|
usernameLabel.textContent = '사용자 이름';
|
|
usernameInput.placeholder = '사용자 이름 선택';
|
|
pwLabel.textContent = '비밀번호';
|
|
submitBtn.textContent = '계정 생성';
|
|
confirmGroup.style.display = 'flex';
|
|
passwordInput.autocomplete = 'new-password';
|
|
passwordInput.placeholder = '비밀번호 선택';
|
|
} else {
|
|
// Normal login
|
|
mode = 'login';
|
|
subtitle.textContent = 'SmallClaw에 로그인';
|
|
migrateNotice.classList.remove('visible');
|
|
usernameGroup.style.display = 'flex';
|
|
usernameLabel.textContent = '사용자 이름';
|
|
usernameInput.placeholder = '사용자 이름 입력';
|
|
pwLabel.textContent = '비밀번호';
|
|
submitBtn.textContent = '로그인';
|
|
confirmGroup.style.display = 'none';
|
|
passwordInput.autocomplete = 'current-password';
|
|
passwordInput.placeholder = '비밀번호 입력';
|
|
}
|
|
|
|
form.style.display = 'flex';
|
|
usernameInput.focus();
|
|
} catch (e) {
|
|
subtitle.textContent = '서버에 연결할 수 없습니다';
|
|
}
|
|
}
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
hideError();
|
|
|
|
const username = usernameInput.value.trim();
|
|
const password = passwordInput.value;
|
|
|
|
if (mode === 'login') {
|
|
if (!username) { showError('사용자 이름을 입력하세요'); return; }
|
|
if (!password) { showError('비밀번호를 입력하세요'); return; }
|
|
} else if (mode === 'setup') {
|
|
if (!username || username.length < 2) { showError('사용자 이름은 최소 2자 이상이어야 합니다'); return; }
|
|
if (!/^[a-zA-Z0-9_-]+$/.test(username)) { showError('사용자 이름: 영문자, 숫자, 하이픈, 밑줄만 사용 가능합니다'); return; }
|
|
if (!password || password.length < 4) { showError('비밀번호는 최소 4자 이상이어야 합니다'); return; }
|
|
if (password !== confirmInput.value) { showError('비밀번호가 일치하지 않습니다'); return; }
|
|
} else if (mode === 'legacy-migrate') {
|
|
if (!username || username.length < 2) { showError('사용자 이름은 최소 2자 이상이어야 합니다'); return; }
|
|
if (!/^[a-zA-Z0-9_-]+$/.test(username)) { showError('사용자 이름: 영문자, 숫자, 하이픈, 밑줄만 사용 가능합니다'); return; }
|
|
if (!password) { showError('현재 비밀번호를 입력하세요'); return; }
|
|
}
|
|
|
|
submitBtn.disabled = true;
|
|
const btnText = submitBtn.textContent;
|
|
submitBtn.textContent = mode === 'setup' ? '계정 생성 중...' : mode === 'legacy-migrate' ? '업그레이드 중...' : '로그인 중...';
|
|
|
|
try {
|
|
let endpoint, body;
|
|
if (mode === 'setup' || mode === 'legacy-migrate') {
|
|
endpoint = '/api/auth/setup';
|
|
body = { username, password };
|
|
} else {
|
|
endpoint = '/api/auth/login';
|
|
body = { username, password };
|
|
}
|
|
const res = await fetch(endpoint, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
});
|
|
const data = await res.json();
|
|
|
|
if (res.ok && data.success) {
|
|
window.location.href = '/';
|
|
} else {
|
|
showError(data.error || '인증 실패');
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = btnText;
|
|
}
|
|
} catch (e) {
|
|
showError('연결 오류 — 다시 시도해 주세요');
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = btnText;
|
|
}
|
|
});
|
|
|
|
usernameInput.addEventListener('input', hideError);
|
|
passwordInput.addEventListener('input', hideError);
|
|
confirmInput.addEventListener('input', hideError);
|
|
|
|
checkStatus();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html> |