连接到远程服务器测试通过。

This commit is contained in:
MiLla 2024-11-19 20:15:57 +08:00 committed by heshunme
parent dc40a82f93
commit 0912abdf29
2 changed files with 4 additions and 4 deletions

View File

@ -30,6 +30,8 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None, s
# 登录路由 # 登录路由
@router.post("/api/s1/login") @router.post("/api/s1/login")
async def login(response: Response, user_data: dict, session: SessionDep): async def login(response: Response, user_data: dict, session: SessionDep):
if user_data.get('username') is None or user_data.get('password') is None:
raise HTTPException(status_code=401, detail="用户名或密码不能为空")
# 查询用户 # 查询用户
user = session.exec(select(User).where(User.username == user_data['username'])).first() user = session.exec(select(User).where(User.username == user_data['username'])).first()

View File

@ -42,11 +42,9 @@ async def add_or_update_user(data: dict, session: SessionDep, current_user: User
user = session.exec(select(User).where(User.username == username, User.tenant_id == current_user.tenant_id)).first() user = session.exec(select(User).where(User.username == username, User.tenant_id == current_user.tenant_id)).first()
if user: if user:
if password == "": if password and password != "":
user.role = role
else:
user.password = password user.password = password
user.role = role user.role = role
session.add(user) session.add(user)
session.commit() session.commit()
return {"detail": "User updated successfully"} return {"detail": "User updated successfully"}