login画面追加

This commit is contained in:
admin
2026-02-07 14:25:28 +09:00
parent 9d1ad5594d
commit 331953bb7f
22 changed files with 763 additions and 135 deletions

41
frontend/js/auth.js Normal file
View File

@@ -0,0 +1,41 @@
/**
* 认证和会话管理
*/
// 检查用户是否已登录
function checkAuth() {
const user = localStorage.getItem("currentUser");
if (!user) {
// 用户未登录,重定向到登录页面
window.location.href = "/login.html";
return false;
}
return true;
}
// 获取当前登录的用户信息
function getCurrentUser() {
const user = localStorage.getItem("currentUser");
return user ? JSON.parse(user) : null;
}
// 保存用户信息(登录时使用)
function setCurrentUser(userData) {
localStorage.setItem("currentUser", JSON.stringify(userData));
}
// 注销用户
function logout() {
localStorage.removeItem("currentUser");
window.location.href = "/login.html";
}
// 在页面加载时检查认证(仅在非登录页面使用)
document.addEventListener("DOMContentLoaded", function () {
const currentPage = window.location.pathname;
// 排除登录页面的检查
if (!currentPage.includes("login.html")) {
checkAuth();
}
});