修复 用户配置不生效
This commit is contained in:
@@ -94,6 +94,11 @@ class RegisterRequest(BaseModel):
|
||||
|
||||
class UserSettingRequest(BaseModel):
|
||||
language: Optional[str] = None
|
||||
nickname: Optional[str] = None
|
||||
avatar: Optional[str] = None
|
||||
timezone: Optional[str] = None
|
||||
password: Optional[str] = None
|
||||
new_password: Optional[str] = None
|
||||
|
||||
|
||||
class TenantInfoRequest(BaseModel):
|
||||
@@ -304,18 +309,23 @@ async def setting_user(request: UserSettingRequest, current_user = Depends(get_c
|
||||
更新用户设置
|
||||
"""
|
||||
update_dict = {}
|
||||
request_data = request.dict()
|
||||
request_data = request.dict(exclude_unset=True)
|
||||
|
||||
if request_data.get("password"):
|
||||
new_password = request_data.get("new_password")
|
||||
if not check_password_hash(current_user.password, decrypt(request_data["password"])):
|
||||
password = request_data.get("password")
|
||||
new_password = request_data.get("new_password")
|
||||
if password is not None or new_password is not None:
|
||||
if not password or not new_password:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Both password and new_password are required!"
|
||||
)
|
||||
if not check_password_hash(current_user.password, decrypt(password)):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Password error!"
|
||||
)
|
||||
|
||||
if new_password:
|
||||
update_dict["password"] = generate_password_hash(decrypt(new_password))
|
||||
update_dict["password"] = generate_password_hash(decrypt(new_password))
|
||||
|
||||
for k in request_data.keys():
|
||||
if k in [
|
||||
|
||||
Reference in New Issue
Block a user