diff --git a/api/api_v1/endpoints/interview.py b/api/api_v1/endpoints/interview.py index 16f928f..932de98 100644 --- a/api/api_v1/endpoints/interview.py +++ b/api/api_v1/endpoints/interview.py @@ -1571,17 +1571,18 @@ async def reset_password(request: Request, return schemas.Msg(code=200, msg='ok') -@router.post("/reset_my_password") +@router.post("/set_userinfo") async def reset_my_password(request: Request, data_in: schemas.UserRestMyPassword, db: AsyncIOMotorDatabase = Depends(get_database), current_user: schemas.User = Depends(deps.get_current_user) ) -> Any: """ - 修改自己的密码 + 修改自己的密码,用户名,电话,邮箱 """ await crud.user.reset_password(db, - schemas.UserRestPassword(user_id=current_user.user_id, password=data_in.password)) + schemas.UserRestPassword(user_id=current_user.user_id, password=data_in.password, + nickname=data_in.nickname,tel=data_in.tel,email=data_in.email)) return schemas.Msg(code=200, msg='ok') diff --git a/crud/crud_user.py b/crud/crud_user.py index 0dade1a..faa05c3 100644 --- a/crud/crud_user.py +++ b/crud/crud_user.py @@ -48,8 +48,19 @@ class CRUDUser(CRUDBase): await db[self.coll_name].insert_one(db_obj.dict(by_alias=True)) async def reset_password(self, db: AsyncIOMotorDatabase, obj_in: schemas.UserRestPassword): - hashed_password = get_password_hash(obj_in.password) - await self.update_one(db, {'user_id': obj_in.user_id}, {'$set': {'hashed_password': hashed_password}}) + date=obj_in.dict() + date.pop('user_id') + if obj_in.password != '': + hashed_password = get_password_hash(obj_in.password) + date.update({'hashed_password': hashed_password}) + dels=[] + for k,v in date.items(): + if v == '': + dels.append(k) + if dels != []: + for i in dels: + date.pop(i) + await self.update_one(db, {'user_id': obj_in.user_id}, {'$set': date}) async def authenticate(self, db: AsyncIOMotorDatabase, name: str, password: str): user_obj = await self.get_by_user(db, name=name) diff --git a/schemas/user.py b/schemas/user.py index e33b34f..6529a2a 100644 --- a/schemas/user.py +++ b/schemas/user.py @@ -40,10 +40,15 @@ class UserLogin(BaseModel): class UserRestPassword(BaseModel): user_id: str = ... password: str = ... - + nickname:str # 用户名 + tel:str # 电话 + email: str # 邮箱 class UserRestMyPassword(BaseModel): password: str = ... + nickname:str # 用户名 + tel:str # 电话 + email: str # 邮箱 class UserCreate(UserBase):