feat(init): 添加完整的认证和业务路由模块
- 实现微信登录、手机号绑定、token验证和登出功能 - 添加打卡系统,支持正常、迟到、请假等状态记录 - 集成课程投票功能,支持多课程选择和评分评论 - 开发反馈系统,支持图文反馈提交和管理员处理 - 构建首页页面模块,动态展示学习资源和个人信息 - 设计计划管理系统,支持周/月/年计划制定和跟踪 - 实现小组计划统计和历史记录查询功能 - 完善用户认证会话管理和数据库交互逻辑
This commit is contained in:
47
user.py
Normal file
47
user.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import re
|
||||
|
||||
from . import db
|
||||
|
||||
|
||||
def make_display_name(group, name):
|
||||
if group and re.match(r"^\d{2}组$", group):
|
||||
return group + name
|
||||
return name
|
||||
|
||||
|
||||
def get_class_groups(user_id):
|
||||
return db.fetch_all(
|
||||
"SELECT c.id AS class_id, c.code AS class_code, c.name AS period, "
|
||||
"g.group_code AS `group`, cg.role_in_group AS role "
|
||||
"FROM class_groups cg "
|
||||
"JOIN classes c ON c.id=cg.class_id "
|
||||
"JOIN `groups` g ON g.id=cg.group_id "
|
||||
"WHERE cg.user_id=%s ORDER BY c.id, g.sort",
|
||||
(user_id,),
|
||||
)
|
||||
|
||||
|
||||
def get_history_groups(user_id):
|
||||
return db.fetch_all(
|
||||
"SELECT og.group_code AS old_group FROM group_history gh "
|
||||
"JOIN classes c ON c.id=gh.class_id "
|
||||
"LEFT JOIN `groups` og ON og.id=gh.old_group_id "
|
||||
"WHERE gh.user_id=%s ORDER BY gh.changed_at DESC",
|
||||
(user_id,),
|
||||
)
|
||||
|
||||
|
||||
def user_payload(user):
|
||||
group = user.get("group") or ""
|
||||
class_groups = get_class_groups(user["id"])
|
||||
history_groups = [h["old_group"] for h in get_history_groups(user["id"])]
|
||||
return {
|
||||
"name": user["name"],
|
||||
"student_id": user["student_id"],
|
||||
"role": user.get("role", "student"),
|
||||
"group": group,
|
||||
"display_name": make_display_name(group, user["name"]),
|
||||
"class_groups": class_groups,
|
||||
"history_groups": history_groups,
|
||||
"first_login": bool(user.get("first_login")),
|
||||
}
|
||||
Reference in New Issue
Block a user