Skip to content

Commit 38c00a6

Browse files
committed
Fix the login password verification
1 parent b93ff19 commit 38c00a6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

backend/app/admin/api/v1/sys/token.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def append_token_detail() -> None:
6161
extra_info = await redis_client.get(f'{settings.TOKEN_EXTRA_INFO_REDIS_PREFIX}:{session_uuid}')
6262
if extra_info:
6363
extra_info = json.loads(extra_info)
64-
if extra_info.get('login_type') != 'swagger':
64+
# 排除 swagger 登录生成的 token
65+
if extra_info.get('swagger') is None:
6566
if username is not None:
6667
if username == extra_info.get('username'):
6768
append_token_detail()

backend/app/admin/service/auth_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AuthService:
3333
"""认证服务类"""
3434

3535
@staticmethod
36-
async def user_verify(db: AsyncSession, username: str, password: str) -> User:
36+
async def user_verify(db: AsyncSession, username: str, password: str | None) -> User:
3737
"""
3838
验证用户名和密码
3939
@@ -45,7 +45,7 @@ async def user_verify(db: AsyncSession, username: str, password: str) -> User:
4545
user = await user_dao.get_by_username(db, username)
4646
if not user:
4747
raise errors.NotFoundError(msg='用户名或密码有误')
48-
elif not password_verify(password, user.password):
48+
elif user.password is None or not password_verify(password, user.password):
4949
raise errors.AuthorizationError(msg='用户名或密码有误')
5050
elif not user.status:
5151
raise errors.AuthorizationError(msg='用户已被锁定, 请联系统管理员')
@@ -65,7 +65,7 @@ async def swagger_login(self, *, obj: HTTPBasicCredentials) -> tuple[str, User]:
6565
str(user.id),
6666
user.is_multi_login,
6767
# extra info
68-
login_type='swagger',
68+
swagger=True,
6969
)
7070
return a_token.access_token, user
7171

0 commit comments

Comments
 (0)