Files
ProxyAuto/templates/login.html

212 lines
7.9 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录 - ProxyAuto Pro</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap" rel="stylesheet">
<style>
.login-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
}
.login-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: 2.5rem;
width: 100%;
max-width: 400px;
box-shadow: var(--shadow-md);
animation: riseIn 480ms var(--ease-smooth);
}
.login-header {
text-align: center;
margin-bottom: 2rem;
}
.login-logo {
font-size: 1.75rem;
font-weight: 700;
color: var(--text);
margin-bottom: 0.5rem;
}
.login-subtitle {
color: var(--text-muted);
font-size: 0.9rem;
}
.captcha-row {
display: flex;
gap: 0.75rem;
align-items: flex-end;
}
.captcha-row .form-group {
flex: 1;
margin-bottom: 0;
}
.captcha-display {
background: var(--surface-soft);
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 0.65rem 1rem;
font-size: 1.1rem;
font-weight: 600;
color: var(--accent);
white-space: nowrap;
user-select: none;
}
.captcha-refresh {
background: none;
border: 1px solid var(--border);
border-radius: var(--radius-md);
padding: 0.65rem;
cursor: pointer;
color: var(--text-muted);
transition: all 200ms var(--ease-smooth);
}
.captcha-refresh:hover {
background: var(--surface-soft);
color: var(--accent);
}
.captcha-refresh svg {
width: 20px;
height: 20px;
display: block;
}
.login-error {
background: var(--error-soft);
color: var(--error);
padding: 0.75rem 1rem;
border-radius: var(--radius-md);
font-size: 0.875rem;
margin-bottom: 1rem;
display: none;
}
.login-error.show {
display: block;
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-card">
<div class="login-header">
<div class="login-logo">ProxyAuto Pro</div>
<div class="login-subtitle">请登录以继续</div>
</div>
<div id="login-error" class="login-error"></div>
<form id="login-form">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" name="username" required autofocus placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" required placeholder="请输入密码">
</div>
<div class="form-group">
<label>验证码</label>
<div class="captcha-row">
<div class="captcha-display" id="captcha-question">{{ captcha_question }}</div>
<button type="button" class="captcha-refresh" onclick="refreshCaptcha()" title="刷新验证码">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="23 4 23 10 17 10"/>
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
</svg>
</button>
<div class="form-group">
<input type="text" id="captcha" name="captcha" required placeholder="答案" style="width: 80px; text-align: center;">
</div>
</div>
</div>
<div class="form-actions" style="margin-top: 1.5rem;">
<button type="submit" class="btn btn-primary btn-lg" style="width: 100%;">
<span class="btn-text">登 录</span>
<span class="btn-loading" style="display: none;">
<svg class="spinner" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="3" fill="none" stroke-dasharray="32" stroke-linecap="round"/>
</svg>
登录中...
</span>
</button>
</div>
</form>
</div>
</div>
<script>
async function refreshCaptcha() {
try {
const response = await fetch('/api/refresh-captcha', { method: 'POST' });
const result = await response.json();
if (result.ok) {
document.getElementById('captcha-question').textContent = result.question;
document.getElementById('captcha').value = '';
}
} catch (error) {
console.error('刷新验证码失败', error);
}
}
document.getElementById('login-form').addEventListener('submit', async function(e) {
e.preventDefault();
const btn = this.querySelector('button[type="submit"]');
const btnText = btn.querySelector('.btn-text');
const btnLoading = btn.querySelector('.btn-loading');
const errorDiv = document.getElementById('login-error');
btn.disabled = true;
btnText.style.display = 'none';
btnLoading.style.display = 'flex';
errorDiv.classList.remove('show');
const formData = {
username: document.getElementById('username').value,
password: document.getElementById('password').value,
captcha: document.getElementById('captcha').value,
};
try {
const response = await fetch('/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
});
const result = await response.json();
if (result.ok) {
window.location.href = '/';
} else {
errorDiv.textContent = result.message;
errorDiv.classList.add('show');
document.getElementById('captcha').value = '';
if (result.new_captcha) {
document.getElementById('captcha-question').textContent = result.new_captcha;
} else {
refreshCaptcha();
}
}
} catch (error) {
errorDiv.textContent = '登录失败,请稍后重试';
errorDiv.classList.add('show');
} finally {
btn.disabled = false;
btnText.style.display = 'inline';
btnLoading.style.display = 'none';
}
});
</script>
</body>
</html>