用户登录功能

This commit is contained in:
2025-12-30 09:39:40 +00:00
parent 9edc0ae2ca
commit 8c3200829a
13 changed files with 539 additions and 23 deletions

View File

@@ -8,6 +8,7 @@ class WorkListAPI {
async request(endpoint, options = {}) {
const url = `${this.baseURL}${endpoint}`;
const config = {
credentials: 'same-origin', // 包含cookies以支持session
headers: {
'Content-Type': 'application/json',
...options.headers
@@ -17,7 +18,7 @@ class WorkListAPI {
try {
const response = await fetch(url, config);
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.error || `HTTP错误: ${response.status}`);
@@ -30,6 +31,31 @@ class WorkListAPI {
}
}
// 认证API
async login(username, password) {
return this.request('/auth/login', {
method: 'POST',
body: JSON.stringify({ username, password })
});
}
async logout() {
return this.request('/auth/logout', {
method: 'POST'
});
}
async checkAuth() {
return this.request('/auth/check');
}
async register(username, password) {
return this.request('/auth/register', {
method: 'POST',
body: JSON.stringify({ username, password })
});
}
// 任务管理API
async getTasks() {
return this.request('/tasks');