From 0a2372a99c72cb82918b87d7c96873866792c69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9A=93=E6=9C=88=E5=BD=92=E5=B0=98?= Date: Wed, 19 Feb 2025 01:21:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=BC=82=E5=B8=B8=EF=BC=8C=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=A4=B1=E8=B4=A5=E6=97=A5=E5=BF=97=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- annotation/log.py | 24 ++++++++++++------------ api/department.py | 2 +- api/log.py | 2 +- api/login.py | 6 +++++- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/annotation/log.py b/annotation/log.py index f69cebb..e237a8a 100644 --- a/annotation/log.py +++ b/annotation/log.py @@ -147,18 +147,18 @@ class Log: # if request_from_swagger or request_from_redoc: # pass # else: - if status == 1: - session_id = request.app.state.session_id - current_user = await User.get_or_none(username=payload.get("username")) - await LoginLog.create( - user_id=current_user.id, - login_ip=host, - login_location=location, - browser=browser, - os=system_os, - status=status, - session_id=session_id - ) + session_id = request.app.state.session_id + status = 1 if request.app.state.login_status else 0 + current_user = await User.get_or_none(username=payload.get("username")) + await LoginLog.create( + user_id=current_user.id, + login_ip=host, + login_location=location, + browser=browser, + os=system_os, + status=status, + session_id=session_id + ) else: if "image" in request.headers.get("Accept", ""): pass diff --git a/api/department.py b/api/department.py index 58f1607..7b7164e 100644 --- a/api/department.py +++ b/api/department.py @@ -74,7 +74,7 @@ async def delete_department_recursive(department_id: str): :return: """ await Department.filter(id=department_id).delete() - sub_departments = await Department.filter(parentId=department_id).all() + sub_departments = await Department.filter(parent_id=department_id).all() for sub_department in sub_departments: await delete_department_recursive(sub_department.id) return True diff --git a/api/log.py b/api/log.py index 24343ce..1df6454 100644 --- a/api/log.py +++ b/api/log.py @@ -33,7 +33,7 @@ async def get_login_log(request: Request, ): online_user_list = await LoginController.get_online_user(request) online_user_list = list( - filter(lambda x: x["user_id"] == current_user.get("id"), jsonable_encoder(online_user_list, ))) + filter(lambda x: x["user_id"] == current_user.get("id"), jsonable_encoder(online_user_list))) user_id = current_user.get("id") result = await LoginLog.filter(user_id=user_id, del_flag=1).offset((page - 1) * pageSize).limit(pageSize).values( id="id", diff --git a/api/login.py b/api/login.py index 14a29ad..3c2c3ff 100644 --- a/api/login.py +++ b/api/login.py @@ -38,6 +38,8 @@ async def login( request: Request, params: CustomOAuth2PasswordRequestForm = Depends() ): + request.app.state.session_id = None + request.app.state.login_status = False user = LoginParams( username=params.username, password=params.password, @@ -47,7 +49,7 @@ async def login( ) captcha_enabled = ( True - if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account.captcha_enabled') + if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account_captcha_enabled') == 'true' else False ) @@ -75,6 +77,7 @@ async def login( ex=timedelta(minutes=5), ) request.app.state.session_id = result["session_id"] + request.app.state.login_status = True if request_from_swagger or request_from_redoc: return {'access_token': result["accessToken"], 'token_type': 'Bearer', "expires_in": result["expiresIn"] * 60} @@ -83,6 +86,7 @@ async def login( result.pop("session_id") result.pop("userInfo") return Response.success(data=result) + request.app.state.login_status = False return Response.failure(msg="登录失败,账号或密码错误!")