From a7f491cef6537097e974bff27108c17fd14af90a Mon Sep 17 00:00:00 2001 From: canglan Date: Tue, 14 Apr 2026 20:59:06 +0800 Subject: [PATCH] =?UTF-8?q?v0.6.1=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cospec/plan/changes/fix-admin-multi-issues/task.md | 7 +++++++ backend/routes/auth.py | 1 + backend/services/auth_service.py | 1 + 3 files changed, 9 insertions(+) diff --git a/.cospec/plan/changes/fix-admin-multi-issues/task.md b/.cospec/plan/changes/fix-admin-multi-issues/task.md index b7bcf93..3b9bd42 100644 --- a/.cospec/plan/changes/fix-admin-multi-issues/task.md +++ b/.cospec/plan/changes/fix-admin-multi-issues/task.md @@ -339,3 +339,10 @@ - 修改 `auth_service.py`:login 方法增加 `user_agent` 参数,在5个退出点(失败次数过多、用户不存在、密码错误、账号禁用、登录成功)均写入 login_logs - 修改 `auth.py`:从 HTTP 请求头获取 user-agent 并传递给 AuthService.login() - 修改 `admin.py`:8个管理操作成功后写入 operation_logs(import_students、add_student、add_points、revoke_record、create_assignment、update_submission、add_attendance、add_admin) + +- [x] 12.11 修复CRITICAL: 登录返回数据缺少student_id导致学生端完全无法工作 + 【目标对象】`backend/services/auth_service.py`、`backend/routes/auth.py` + 【修改目的】登录成功后返回给前端的数据中没有 student_id 字段,导致 index.php 无法传递 student_id 给 save_session.php,Session 中缺少 student_id,学生端所有页面 $student_id 为 null,所有 API 调用路径变成 /api/student/conduct/null 导致失败。这是学生端显示"假数据"的根本原因 + 【修改方式】 + - auth_service.py: login 方法返回字典添加 `"student_id": user["student_id"]` + - auth.py: 登录路由 success_response data 字典添加 `"student_id": result.get("student_id")` diff --git a/backend/routes/auth.py b/backend/routes/auth.py index fd39d65..44a5e14 100644 --- a/backend/routes/auth.py +++ b/backend/routes/auth.py @@ -46,6 +46,7 @@ async def login(request: LoginRequest, http_request: Request): "username": result["username"], "real_name": result["real_name"], "user_type": result["user_type"], + "student_id": result.get("student_id"), "role": result.get("role"), "need_change_password": result["need_change_password"], "redirect": result["redirect"] diff --git a/backend/services/auth_service.py b/backend/services/auth_service.py index 5a08578..25466eb 100644 --- a/backend/services/auth_service.py +++ b/backend/services/auth_service.py @@ -94,6 +94,7 @@ class AuthService: "username": user["username"], "real_name": user["real_name"], "user_type": user["user_type"], + "student_id": user["student_id"], "role": role, "need_change_password": user["need_change_password"] == 1, "redirect": redirect