用户登录功能
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user