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="登录失败,账号或密码错误!")