This commit is contained in:
Ubuntu
2026-07-03 16:58:28 +08:00
commit 32b43f85bd
6240 changed files with 1987678 additions and 0 deletions
+176
View File
@@ -0,0 +1,176 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SSO 统一登录</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);min-height:100vh;display:flex;align-items:center;justify-content:center}
.card{background:#fff;padding:40px;border-radius:16px;box-shadow:0 20px 60px rgba(0,0,0,.3);width:100%;max-width:400px}
h1{text-align:center;margin-bottom:8px;color:#333;font-size:24px}
p.sub{text-align:center;color:#888;margin-bottom:28px;font-size:14px}
.input-group{margin-bottom:20px}
label{display:block;margin-bottom:6px;color:#555;font-size:14px;font-weight:500}
input{width:100%;padding:12px 14px;border:1px solid #ddd;border-radius:8px;font-size:15px;transition:border .2s}
input:focus{outline:none;border-color:#667eea}
button{width:100%;padding:14px;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:#fff;border:none;border-radius:8px;font-size:16px;cursor:pointer;transition:opacity .2s}
button:hover{opacity:.9}
button.secondary{background:#f3f4f6;color:#374151;margin-top:10px}
button.secondary:hover{background:#e5e7eb;opacity:1}
.error{background:#fee2e2;color:#991b1b;padding:12px;border-radius:8px;margin-bottom:16px;font-size:14px;display:none}
.success{background:#d1fae5;color:#065f46;padding:12px;border-radius:8px;margin-bottom:16px;font-size:14px;display:none}
.link{text-align:center;margin-top:16px;font-size:14px;color:#667eea;cursor:pointer;text-decoration:underline}
.link:hover{color:#764ba2}
</style>
</head>
<body>
<div class="card">
<h1 id="pageTitle">🔐 SSO 统一登录</h1>
<p class="sub" id="pageSub">登录后将自动跳转回原系统</p>
<div class="error" id="error"></div>
<div class="success" id="success"></div>
<!-- 登录表单 -->
<form id="loginForm">
<div class="input-group">
<label>用户名</label>
<input type="text" id="username" value="admin" required autofocus>
</div>
<div class="input-group">
<label>密码</label>
<input type="password" id="password" required>
</div>
<button type="submit">登 录</button>
<div class="link" id="toChangePwd">修改密码</div>
</form>
<!-- 修改密码表单 -->
<form id="changePwdForm" style="display:none">
<div class="input-group">
<label>用户名</label>
<input type="text" id="cp_username" required>
</div>
<div class="input-group">
<label>旧密码</label>
<input type="password" id="cp_old_password" required>
</div>
<div class="input-group">
<label>新密码</label>
<input type="password" id="cp_new_password" required minlength="6">
</div>
<div class="input-group">
<label>确认新密码</label>
<input type="password" id="cp_confirm_password" required>
</div>
<button type="submit">确认修改</button>
<button type="button" class="secondary" id="toLogin">返回登录</button>
</form>
</div>
<script>
const redirect = "{{redirect}}";
const errorDiv = document.getElementById('error');
const successDiv = document.getElementById('success');
const loginForm = document.getElementById('loginForm');
const changePwdForm = document.getElementById('changePwdForm');
const pageTitle = document.getElementById('pageTitle');
const pageSub = document.getElementById('pageSub');
function showError(msg) {
errorDiv.textContent = msg;
errorDiv.style.display = 'block';
successDiv.style.display = 'none';
}
function showSuccess(msg) {
successDiv.textContent = msg;
successDiv.style.display = 'block';
errorDiv.style.display = 'none';
}
function clearMsg() {
errorDiv.style.display = 'none';
successDiv.style.display = 'none';
}
// 切换显示
document.getElementById('toChangePwd').addEventListener('click', () => {
loginForm.style.display = 'none';
changePwdForm.style.display = 'block';
pageTitle.textContent = '🔑 修改密码';
pageSub.textContent = '输入账号和旧密码以修改';
clearMsg();
});
document.getElementById('toLogin').addEventListener('click', () => {
changePwdForm.style.display = 'none';
loginForm.style.display = 'block';
pageTitle.textContent = '🔐 SSO 统一登录';
pageSub.textContent = '登录后将自动跳转回原系统';
clearMsg();
});
// 登录
loginForm.addEventListener('submit', async (e) => {
e.preventDefault();
clearMsg();
const form = new URLSearchParams();
form.append('username', document.getElementById('username').value);
form.append('password', document.getElementById('password').value);
form.append('redirect', redirect);
try {
const res = await fetch('/api/login', {method:'POST', body:form});
const data = await res.json();
if (res.ok) {
window.location.href = redirect || '/';
} else {
showError(data.detail || '登录失败');
}
} catch (err) {
showError('网络错误');
}
});
// 修改密码
changePwdForm.addEventListener('submit', async (e) => {
e.preventDefault();
clearMsg();
const username = document.getElementById('cp_username').value;
const old_password = document.getElementById('cp_old_password').value;
const new_password = document.getElementById('cp_new_password').value;
const confirm_password = document.getElementById('cp_confirm_password').value;
if (new_password !== confirm_password) {
showError('两次新密码不一致');
return;
}
if (new_password.length < 6) {
showError('新密码至少6位');
return;
}
const form = new URLSearchParams();
form.append('username', username);
form.append('old_password', old_password);
form.append('new_password', new_password);
try {
const res = await fetch('/api/change-password', {method:'POST', body:form});
const data = await res.json();
if (res.ok) {
showSuccess('密码修改成功,请用新密码登录');
setTimeout(() => {
changePwdForm.style.display = 'none';
loginForm.style.display = 'block';
pageTitle.textContent = '🔐 SSO 统一登录';
pageSub.textContent = '登录后将自动跳转回原系统';
clearMsg();
}, 1500);
} else {
showError(data.detail || '修改失败');
}
} catch (err) {
showError('网络错误');
}
});
</script>
</body>
</html>