Files
SenSu/static/web_panel/js/api.js
T
AskaEth e6875f0b4b Initial commit: SenSu Alpha 0.2.0
- 13-service async plugin framework
- Textual TUI with CLI fallback
- Plugin hot-reload + permission system
- Web management panel (aiohttp)
- Bridge-based inter-module communication
- 10 regression tests

Fixes applied:
- PBKDF2-SHA256 auth (was plain SHA256)
- Auth bypass removed (was allow-all on fail)
- Bare excepts replaced with logged errors
- CatFramework/DreamSu -> SenSu naming unified
- ServiceManager: health checks + startup_order
- Env var credentials (SENSU_ADMIN_PASSWORD etc)
2026-06-10 12:28:05 +08:00

33 lines
1.0 KiB
JavaScript

const BASE = '/panel';
export const api = {
get: async (url) => {
const res = await fetch(`${BASE}${url}`, { credentials: 'include' });
return res.json();
},
post: async (url, data) => {
const res = await fetch(`${BASE}${url}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify(data)
});
return res.json();
}
};
export async function initAuth() {
// 登录逻辑绑定到 DOM
const loginForm = document.querySelector('#login-form');
if(loginForm) {
loginForm.addEventListener('submit', async (e) => {
e.preventDefault();
const u = document.getElementById('username').value;
const p = document.getElementById('password').value;
const res = await api.post('/api/login', { username: u, password: p });
if (res.success) location.reload(); // 登录成功刷新
});
}
return await api.get('/api/auth/status');
}