关联user
This commit is contained in:
parent
2a03a20ce7
commit
58eafaaf7f
@ -108,7 +108,7 @@ async def edit_profile(request: Request,
|
||||
"""
|
||||
编辑用户资料
|
||||
"""
|
||||
await crud.user.edit_profile(db, data_in)
|
||||
await crud.user.edit_profile(db, data_in, user_id=request.user.id)
|
||||
return schemas.Msg(code=0, msg='ok', data=data_in)
|
||||
|
||||
|
||||
|
@ -18,11 +18,11 @@ class CRUDUser(CRUDBase):
|
||||
res = await db[self.coll_name].find_one({'name': name})
|
||||
return res
|
||||
|
||||
async def edit_profile(self, db: AsyncIOMotorDatabase, data_id: schemas.UserProfileEdit):
|
||||
async def edit_profile(self, db: AsyncIOMotorDatabase, data_id: schemas.UserProfileEdit,user_id):
|
||||
if data_id.nickname:
|
||||
await self.update_one(db, {'_id': data_id.user_id}, {'$set': data_id.nickname})
|
||||
if data_id.nickname:
|
||||
await self.update_one(db, {'_id': data_id.user_id}, {'$set': data_id.tel})
|
||||
await self.update_one(db, {'_id': user_id}, {'$set': {'nickname':data_id.nickname}})
|
||||
if data_id.tel:
|
||||
await self.update_one(db, {'_id': user_id}, {'$set': {'tel':data_id.tel}})
|
||||
|
||||
async def update_login_time(self, db, name):
|
||||
await self.update_one(db, {'name': name},
|
||||
@ -45,7 +45,8 @@ class CRUDUser(CRUDBase):
|
||||
await self.update_one(db, {'name': obj_in.username}, {'$set': {'hashed_password': hashed_password}})
|
||||
|
||||
async def authenticate(self, db: AsyncIOMotorDatabase, name: str, password: str):
|
||||
user_obj = UserDBRW(**await self.get_by_user(db, name=name))
|
||||
user_obj = await self.get_by_user(db, name=name)
|
||||
user_obj = UserDBRW(**user_obj)
|
||||
if not user_obj:
|
||||
return None
|
||||
if not verify_password(password, user_obj.hashed_password):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import Optional, List
|
||||
from typing import Optional, List, Any
|
||||
|
||||
from schemas.base import DBBase
|
||||
|
||||
@ -15,7 +15,6 @@ class UserBase(BaseModel):
|
||||
|
||||
|
||||
class UserProfileEdit(BaseModel):
|
||||
user_id: str
|
||||
nickname: str = None
|
||||
tel: str = None
|
||||
|
||||
@ -56,7 +55,7 @@ class UserDB(DBBase):
|
||||
is_superuser: bool = False
|
||||
name: str
|
||||
nickname: str = ''
|
||||
tel: str = ''
|
||||
tel: Any = ''
|
||||
last_login_ts: str = '尚未登录'
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user