diff --git a/Config/daily_out_temps.docx b/Config/daily_out_temps.docx index a7841dc..c3adc2d 100644 Binary files a/Config/daily_out_temps.docx and b/Config/daily_out_temps.docx differ diff --git a/Crud/UserCrud.py b/Crud/UserCrud.py index 8e25b43..9e6899f 100644 --- a/Crud/UserCrud.py +++ b/Crud/UserCrud.py @@ -61,6 +61,11 @@ def change_user_daily_fill_notice(db: Session, email: str, daily_fill_notice: bo db.commit() +def set_user_openid(db: Session, email: str, openid: str): + db.query(User).filter_by(email=email).update({'openid': openid}) + db.commit() + + # 根据email从用户信息表内配置用户数据,相当于用户接入后的数据库操作 def update_user_info_from_email(db: Session, email: str): user_info = db.query(UserInfo).filter_by(email=email).first() diff --git a/Models/UserModel.py b/Models/UserModel.py index 20f35a7..46113bc 100644 --- a/Models/UserModel.py +++ b/Models/UserModel.py @@ -6,7 +6,7 @@ from Utils.SqlAlchemyUtils import Base class User(Base): __tablename__ = "user" - # openid = Column(String(255), primary_key=True, comment="用户OpenID") + openid = Column(String(255), primary_key=True, comment="用户OpenID") email = Column(String(255), primary_key=True, comment="邮箱") phone = Column(String(255), comment="手机号") name = Column(String(32), comment="用户名") diff --git a/Router/UserRouter.py b/Router/UserRouter.py index b405fc5..7c9e860 100644 --- a/Router/UserRouter.py +++ b/Router/UserRouter.py @@ -256,6 +256,17 @@ def change_user_daily_fill_notice(body: UserSchemas.ChangeUserDailyFillNoticeReq return {"msg": "修改成功", "state": 1} +@router.post("/set_user_openid", tags=["用户接口"], summary="设置用户openid") +def set_user_openid(body: UserSchemas.SetUserOpenidReq, + token_data: TokenData = Depends(token_data_depend), + db: Session = Depends(get_db)): + openid = code2Session(body.code).openid + if not openid: + raise HTTPException(detail="code无效", status_code=303) + UserCrud.set_user_openid(db, token_data.email, openid) + return {"msg": "修改成功", "state": 1} + + @router.post("/get_user_can_watch_department", tags=["获取用户可查看部门列表"], summary=['查询']) def get_user_can_watch_department(token_data: TokenData = Depends(token_data_depend), db: Session = Depends(get_db)): print(token_data) diff --git a/Schemas/UserSchemas.py b/Schemas/UserSchemas.py index f1239a4..2fee0bc 100644 --- a/Schemas/UserSchemas.py +++ b/Schemas/UserSchemas.py @@ -53,6 +53,7 @@ class GetUserInfoRes(BaseModel): email: Optional[str] post: Optional[str] phone: Optional[str] + openid: Optional[str] post_list: Optional[List[PostInfo]] name: Optional[str] department: Optional[str] @@ -77,6 +78,7 @@ class UserInfoChange(BaseModel): email: str name: Optional[str] post: Optional[str] + openid: Optional[str] daily_fill_notice: Optional[bool] manage_departments: Optional[str] department: Optional[str] @@ -90,6 +92,7 @@ class UserInfo(BaseModel): post: str phone: Optional[str] daily_fill_notice: Optional[bool] + openid: Optional[str] manage_departments: Optional[str] department: Optional[str] registered: Optional[bool] @@ -101,6 +104,7 @@ class UserFullInfo(BaseModel): post_list: Optional[List[PostInfo]] name: Optional[str] phone: Optional[str] + openid: Optional[str] department: Optional[str] daily_fill_notice: Optional[bool] daily_fill_notice: Optional[bool] @@ -126,6 +130,11 @@ class LoginByPhoneReq(BaseModel): code: str +class SetUserOpenidReq(BaseModel): + # openid: str + code:str + + class GetPhoneVerifyCodeReq(BaseModel): phone: str