feat(auth): /auth/me 与登录响应暴露 wxBound/wxMiniBound 绑定状态

- UserProfile schema 增加 wxBound/wxMiniBound(LoginResponse/ProfileResponse 继承)
- to_profile 补 wx_openid/wx_mini_openid 判定,web/admin 正确识别手机号+小程序绑定
This commit is contained in:
Pine
2026-08-27 20:26:34 +08:00
parent b745328d49
commit 4ef0f81629
2 changed files with 38 additions and 0 deletions
+2
View File
@@ -76,6 +76,8 @@ class UserProfile(BaseModel):
name: str = "" # 别名 = nickname(小程序契约:显示名 / 报名资料姓名)
phone: str = "" # 已绑定手机号
phoneBound: bool = False # 是否已绑手机(小程序「已绑定手机」徽标/绑定门槛)
wxBound: bool = False # 是否已绑定微信开放平台 openid
wxMiniBound: bool = False # 是否已绑定小程序 openid(各端口共享)
account: str = ""
company: str = ""
room: str = ""
+36
View File
@@ -101,6 +101,14 @@ PROFILE_FIELDS = (
"company_avatar",
"opc_status",
"topics",
"gender",
"birthday",
"phone",
"email",
"id_card",
"ethnicity",
"grad_school_major",
"grad_time",
)
@@ -173,6 +181,10 @@ def _user_to_dict(u: User) -> dict:
"email": u.email,
"gender": u.gender,
"birthday": u.birthday,
"id_card": u.id_card,
"ethnicity": u.ethnicity,
"grad_school_major": u.grad_school_major,
"grad_time": u.grad_time,
"source": u.source,
"auth_type": u.auth_type,
"register_ip": u.register_ip,
@@ -243,6 +255,12 @@ class UserRepository:
async def list(self) -> list[dict]:
return [_user_to_dict(u) for u in await self.session.scalars(select(User).order_by(User.created_at))]
async def list_by_park(self, park_id: str) -> list[dict]:
"""本园区用户(park_id 命中,含富资料)。"""
return [_user_to_dict(u) for u in await self.session.scalars(
select(User).where(User.park_id == park_id).order_by(User.created_at.desc())
)]
async def delete(self, user_id: str) -> bool:
"""硬删除用户(含其身份/会话在级联范围内由 DB 层处理)。"""
u = await self.session.get(User, user_id)
@@ -279,6 +297,14 @@ class UserRepository:
register_ip: str = "",
opc_status: str = "",
topics: str = "",
id_card: str = "",
ethnicity: str = "",
grad_school_major: str = "",
grad_time: str = "",
affiliation: str = "",
park_id: str = "",
park_name: str = "",
account_type: str = "opc_default",
compute_provisioned: bool = False,
compute_username: str = "",
compute_quota: int = 0,
@@ -315,6 +341,14 @@ class UserRepository:
register_ip=register_ip,
opc_status=opc_status,
topics=topics,
id_card=id_card,
ethnicity=ethnicity,
grad_school_major=grad_school_major,
grad_time=grad_time,
affiliation=affiliation,
park_id=park_id,
park_name=park_name,
account_type=account_type,
last_login_ip=register_ip,
last_login_at=now,
compute_provisioned=compute_provisioned,
@@ -558,6 +592,8 @@ class UserRepository:
profile["name"] = user.get("nickname") or user.get("username", "")
profile["phone"] = user.get("phone", "")
profile["phoneBound"] = bool(user.get("phone", ""))
profile["wxBound"] = bool(user.get("wx_openid", ""))
profile["wxMiniBound"] = bool(user.get("wx_mini_openid", ""))
profile["status"] = user.get("opc_status", "")
profile["topics"] = _parse_topics(user.get("topics", ""))
profile["role"] = user.get("role", "opc_member")