Skip to content

Fix the login password verification #568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/app/admin/api/v1/sys/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def append_token_detail() -> None:
extra_info = await redis_client.get(f'{settings.TOKEN_EXTRA_INFO_REDIS_PREFIX}:{session_uuid}')
if extra_info:
extra_info = json.loads(extra_info)
if extra_info.get('login_type') != 'swagger':
# 排除 swagger 登录生成的 token
if extra_info.get('swagger') is None:
if username is not None:
if username == extra_info.get('username'):
append_token_detail()
Expand Down
14 changes: 10 additions & 4 deletions backend/app/admin/service/auth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AuthService:
"""认证服务类"""

@staticmethod
async def user_verify(db: AsyncSession, username: str, password: str) -> User:
async def user_verify(db: AsyncSession, username: str, password: str | None) -> User:
"""
验证用户名和密码

Expand All @@ -45,10 +45,16 @@ async def user_verify(db: AsyncSession, username: str, password: str) -> User:
user = await user_dao.get_by_username(db, username)
if not user:
raise errors.NotFoundError(msg='用户名或密码有误')
elif not password_verify(password, user.password):

if user.password is None:
raise errors.AuthorizationError(msg='用户名或密码有误')
elif not user.status:
else:
if not password_verify(password, user.password):
raise errors.AuthorizationError(msg='用户名或密码有误')

if not user.status:
raise errors.AuthorizationError(msg='用户已被锁定, 请联系统管理员')

return user

async def swagger_login(self, *, obj: HTTPBasicCredentials) -> tuple[str, User]:
Expand All @@ -65,7 +71,7 @@ async def swagger_login(self, *, obj: HTTPBasicCredentials) -> tuple[str, User]:
str(user.id),
user.is_multi_login,
# extra info
login_type='swagger',
swagger=True,
)
return a_token.access_token, user

Expand Down