From 6647e5cd04f9ec91f530cdf5f3bd03538cd4b1e8 Mon Sep 17 00:00:00 2001 From: jimmy-sketch Date: Thu, 24 Jul 2025 12:30:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=86=20app/=20=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E6=89=80=E6=9C=89=E4=BB=A3=E7=A0=81=E4=B8=AD=E4=B8=8Esql?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E6=89=80=E6=9C=89=E9=9A=90=E5=BC=8F?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E6=9B=BF=E6=8D=A2=E4=B8=BA?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- app/auth.py | 2 +- app/database.py | 1 + app/router/auth.py | 5 +++-- app/utils.py | 6 +++--- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bb18dc3..a6bf882 100644 --- a/.gitignore +++ b/.gitignore @@ -205,4 +205,5 @@ cython_debug/ marimo/_static/ marimo/_lsp/ __marimo__/ -bancho.py-master/* \ No newline at end of file +bancho.py-master/* +.vscode/settings.json diff --git a/app/auth.py b/app/auth.py index 45afba7..7bebdd5 100644 --- a/app/auth.py +++ b/app/auth.py @@ -84,7 +84,7 @@ def authenticate_user_legacy(db: Session, name: str, password: str) -> Optional[ return None # 3. 验证密码 - if not user.pw_bcrypt: + if not (user.pw_bcrypt is None and user.pw_bcrypt != ""): return None # 4. 检查缓存 diff --git a/app/database.py b/app/database.py index 31d3d6a..5bf536a 100644 --- a/app/database.py +++ b/app/database.py @@ -147,6 +147,7 @@ class User(Base): lazer_replays_watched = relationship( "LazerUserReplaysWatched", back_populates="user", cascade="all, delete-orphan" ) + # ============================================ diff --git a/app/router/auth.py b/app/router/auth.py index afe4cf2..634a463 100644 --- a/app/router/auth.py +++ b/app/router/auth.py @@ -60,7 +60,7 @@ async def oauth_token( # 存储令牌 store_token( db, - user.id, + getattr(user, "id"), access_token, refresh_token_str, settings.ACCESS_TOKEN_EXPIRE_MINUTES * 60, @@ -92,9 +92,10 @@ async def oauth_token( new_refresh_token = generate_refresh_token() # 更新令牌 + user_id = int(getattr(token_record, 'user_id')) store_token( db, - token_record.user_id, + user_id, access_token, new_refresh_token, settings.ACCESS_TOKEN_EXPIRE_MINUTES * 60, diff --git a/app/utils.py b/app/utils.py index 75021a8..7eab233 100644 --- a/app/utils.py +++ b/app/utils.py @@ -58,9 +58,9 @@ def convert_db_user_to_api_user( user_stats = create_default_lazer_statistics(ruleset) # 获取国家信息 - country_code = db_user.country_code if db_user.country_code else "XX" + country_code = db_user.country_code if db_user.country_code is not None else "XX" - country = Country(code=country_code, name=get_country_name(country_code)) + country = Country(code=str(country_code), name=get_country_name(str(country_code))) # 获取 Kudosu 信息 kudosu = Kudosu(available=0, total=0) @@ -346,7 +346,7 @@ def convert_db_user_to_api_user( id=user_id, username=user_name, avatar_url=avatar_url, - country_code=country_code, + country_code=str(country_code), default_group=profile.default_group if profile else "default", is_active=profile.is_active if profile else True, is_bot=profile.is_bot if profile else False,