<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - SamiGPT Configuration Manager</title>
<link rel="stylesheet" href="/static/style.css">
<style>
.login-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-box {
background: white;
padding: 40px;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 100%;
max-width: 400px;
}
.login-box h1 {
text-align: center;
color: #333;
margin-bottom: 10px;
}
.login-box p {
text-align: center;
color: #666;
margin-bottom: 30px;
font-size: 14px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #333;
}
.form-group input {
width: 100%;
padding: 12px 15px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
transition: border-color 0.3s;
}
.form-group input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.btn-login {
width: 100%;
padding: 12px;
background: #667eea;
color: white;
border: none;
border-radius: 6px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: background 0.3s;
}
.btn-login:hover {
background: #5568d3;
}
.btn-login:disabled {
background: #6c757d;
cursor: not-allowed;
}
.alert {
margin-bottom: 20px;
padding: 12px 15px;
border-radius: 6px;
font-size: 14px;
display: none;
}
.alert.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-box">
<h1>SamiGPT</h1>
<p>Configuration Manager</p>
<div class="alert error" id="alert"></div>
<form id="login-form">
<div class="form-group">
<label for="secret">Admin Secret</label>
<input
type="password"
id="secret"
name="secret"
placeholder="Enter admin secret"
required
autofocus
>
</div>
<button type="submit" class="btn-login" id="login-btn">Login</button>
</form>
</div>
</div>
<script>
document.getElementById('login-form').addEventListener('submit', async (e) => {
e.preventDefault();
const secret = document.getElementById('secret').value;
const loginBtn = document.getElementById('login-btn');
const alert = document.getElementById('alert');
if (!secret) {
showAlert('Please enter the admin secret', 'error');
return;
}
loginBtn.disabled = true;
loginBtn.textContent = 'Logging in...';
alert.style.display = 'none';
try {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ secret: secret }),
});
if (response.ok) {
const result = await response.json();
if (result.success) {
// Redirect to main page
window.location.href = '/';
} else {
showAlert('Login failed: ' + (result.message || 'Unknown error'), 'error');
loginBtn.disabled = false;
loginBtn.textContent = 'Login';
}
} else {
const error = await response.json();
showAlert('Login failed: ' + (error.detail || 'Invalid secret'), 'error');
loginBtn.disabled = false;
loginBtn.textContent = 'Login';
}
} catch (error) {
showAlert('Login failed: ' + error.message, 'error');
loginBtn.disabled = false;
loginBtn.textContent = 'Login';
}
});
function showAlert(message, type) {
const alert = document.getElementById('alert');
alert.textContent = message;
alert.className = `alert ${type}`;
alert.style.display = 'block';
}
// Check if already authenticated
(async () => {
try {
const response = await fetch('/api/auth/status');
const result = await response.json();
if (result.authenticated) {
window.location.href = '/';
}
} catch (error) {
// Ignore errors
}
})();
</script>
</body>
</html>