Files
StarlightRadio/public/login.html
T
Xiao-no-love f0fe50e484 feat: StarLight 第三方登录 + 安全加固 + 循环池 + 热配置
功能:
- StarLight Yggdrasil 第三方登录(后端中转,accessToken 不落地)
- 管理员可视化权限管理(用户列表 + 一键授予/移出)
- 设置页热配置(11 项可编辑,立即生效)
- 循环池(每流独立手动歌单,队列空时随机不重复抽取)
- 登录页统一主站浅色风格
- 全站改名「Starlight专属电台」
- 删除关于页

安全:
- 全局 CSRF 防护(双提交 Cookie)
- 登录限流防 XFF 伪造、错误信息脱敏
- 权限中间件 requireAdminForWrites(读放行/写 admin)
- 密码哈希存储(scrypt/sha256)
- SSRF 防护(封面下载域名白名单)
- 空 catch 加日志、SSE 连接上限

修复:
- 多角色账号 selectedProfile 缺失
- 普通用户越权删歌(V4)
- streams 写操作越权(V9)
- 设置页布局溢出

测试:38 项全绿(api16 / e2e17 / write5)
2026-10-06 16:37:03 +08:00

276 lines
9.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>Starlight专属电台</title>
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/vendor/bootstrap-icons.css" />
<style>
/* ===== 与主页面一致的浅色设计 token ===== */
:root {
--bg: #f4f5f9;
--surface: #fff;
--surface-hover: #fafbff;
--accent: #4f6ef7;
--accent-hover: #3d5ce0;
--accent-light: #eef1fe;
--accent-glow: rgba(79, 110, 247, 0.14);
--text-primary: #0f1225;
--text-secondary: #5a607f;
--text-muted: #9499b8;
--border: #e8eaf2;
--border-light: #f0f1f6;
--danger: #ef4565;
--danger-light: #fef0f2;
--success: #30a46c;
--radius-sm: 10px;
--radius: 14px;
--radius-lg: 20px;
--radius-xl: 28px;
--radius-pill: 999px;
--shadow-sm: 0 2px 8px rgba(15, 18, 37, 0.06);
--shadow: 0 4px 20px rgba(15, 18, 37, 0.07);
--shadow-lg: 0 8px 40px rgba(15, 18, 37, 0.1);
--shadow-accent: 0 4px 16px rgba(79, 110, 247, 0.25);
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100dvh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
background: var(--bg);
color: var(--text-primary);
font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont,
"Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
.card {
width: 100%;
max-width: 400px;
background: var(--surface);
border: 1px solid var(--border-light);
border-radius: var(--radius-xl);
box-shadow: var(--shadow-lg);
padding: 40px 34px;
animation: cardRise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes cardRise {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: translateY(0); }
}
.logo {
width: 72px;
height: 72px;
margin: 0 auto 18px;
border-radius: var(--radius-lg);
background: var(--accent-light);
display: flex;
align-items: center;
justify-content: center;
font-size: 34px;
box-shadow: var(--shadow-accent);
}
h1 {
text-align: center;
font-size: 1.35rem;
margin: 0 0 6px;
font-weight: 700;
color: var(--text-primary);
}
.sub {
text-align: center;
color: var(--text-secondary);
font-size: 0.86rem;
margin-bottom: 30px;
}
label {
display: block;
font-size: 0.8rem;
font-weight: 600;
color: var(--text-secondary);
margin-bottom: 7px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 12px 14px;
background: var(--bg);
border: 1.5px solid var(--border);
border-radius: var(--radius-sm);
color: var(--text-primary);
font-size: 0.92rem;
font-family: inherit;
outline: none;
transition: border-color .18s, box-shadow .18s, background .18s;
}
input[type="text"]:focus, input[type="password"]:focus {
border-color: var(--accent);
background: var(--surface);
box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder { color: var(--text-muted); }
.field { margin-bottom: 18px; }
.btn-primary {
width: 100%;
margin-top: 6px;
padding: 13px;
background: var(--accent);
border: none;
border-radius: var(--radius-sm);
color: #fff;
font-size: 0.95rem;
font-weight: 700;
font-family: inherit;
cursor: pointer;
transition: background .18s, box-shadow .18s, transform .1s;
box-shadow: var(--shadow-accent);
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; box-shadow: none; }
.error {
margin-top: 14px;
color: var(--danger);
font-size: 0.82rem;
text-align: center;
min-height: 18px;
}
.hint {
margin-top: 20px;
text-align: center;
font-size: 0.78rem;
color: var(--text-muted);
}
.hint a { color: var(--accent); text-decoration: none; font-weight: 600; }
.hint a:hover { text-decoration: underline; }
details {
margin-top: 22px;
border-top: 1px solid var(--border-light);
padding-top: 18px;
}
summary {
cursor: pointer;
font-size: 0.78rem;
color: var(--text-muted);
list-style: none;
user-select: none;
}
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸ "; transition: transform .2s; }
details[open] summary::before { content: "▾ "; }
details .field { margin-top: 14px; }
.btn-secondary {
width: 100%;
margin-top: 4px;
padding: 11px;
background: var(--surface);
border: 1.5px solid var(--border);
border-radius: var(--radius-sm);
color: var(--text-secondary);
font-size: 0.88rem;
font-weight: 600;
font-family: inherit;
cursor: pointer;
transition: all .18s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { opacity: .6; cursor: default; }
</style>
</head>
<body>
<div class="card">
<div class="logo">🎵</div>
<h1>Starlight专属电台</h1>
<div class="sub">使用 StarLight 账号登录</div>
<form id="loginForm">
<div class="field">
<label for="username">StarLight 用户名</label>
<input type="text" id="username" placeholder="邮箱 / 用户名" autocomplete="username" autofocus />
</div>
<div class="field">
<label for="password">密码</label>
<input type="password" id="password" placeholder="请输入密码" autocomplete="current-password" />
</div>
<button type="submit" class="btn-primary" id="submitBtn">
<i class="bi bi-box-arrow-in-right"></i> 登录
</button>
</form>
<div class="error" id="error"></div>
<div class="hint">
还没有账号?<a href="https://skin.starlight.cool" target="_blank" rel="noopener">前往 StarLight 注册</a>
</div>
<details>
<summary>管理员应急登录</summary>
<div class="field">
<label for="emergencyPassword">管理员密码</label>
<input type="password" id="emergencyPassword" placeholder="应急管理密码" autocomplete="off" />
</div>
<button type="button" class="btn-secondary" id="emergencyBtn">应急登录</button>
</details>
</div>
<script>
const form = document.getElementById("loginForm");
const usernameInput = document.getElementById("username");
const passwordInput = document.getElementById("password");
const btn = document.getElementById("submitBtn");
const err = document.getElementById("error");
const emergencyBtn = document.getElementById("emergencyBtn");
const emergencyPassword = document.getElementById("emergencyPassword");
async function doLogin(payload) {
err.textContent = "";
try {
const r = await fetch("/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const data = await r.json();
if (r.ok && data.ok) {
window.location.href = "/";
return true;
}
err.textContent = data.error || "登录失败";
return false;
} catch (e) {
err.textContent = "网络错误,请重试";
return false;
}
}
form.addEventListener("submit", async (e) => {
e.preventDefault();
const username = usernameInput.value.trim();
const password = passwordInput.value;
if (!username || !password) {
err.textContent = "请输入用户名和密码";
return;
}
btn.disabled = true;
await doLogin({ username, password });
btn.disabled = false;
});
emergencyBtn.addEventListener("click", async () => {
const password = emergencyPassword.value;
if (!password) { err.textContent = "请输入管理员密码"; return; }
emergencyBtn.disabled = true;
await doLogin({ password });
emergencyBtn.disabled = false;
});
</script>
</body>
</html>