diff --git a/backend/app/api/v1/services/system/auth_service.py b/backend/app/api/v1/services/system/auth_service.py index aa1c1734..a6ac6889 100644 --- a/backend/app/api/v1/services/system/auth_service.py +++ b/backend/app/api/v1/services/system/auth_service.py @@ -94,7 +94,7 @@ class LoginService: name=user.name, user_name=user.username, ipaddr=request.client.host, - login_location=IpLocalUtil.get_ip_location(str(request.client.host)), + login_location=IpLocalUtil.get_ip_location(request.client.host), os=user_agent.os.family, browser = user_agent.browser.family, login_time=user.last_login diff --git a/backend/app/core/router_class.py b/backend/app/core/router_class.py index 19054d98..18759b4b 100644 --- a/backend/app/core/router_class.py +++ b/backend/app/core/router_class.py @@ -68,7 +68,7 @@ class OperationLogRoute(APIRoute): current_user_id = request.scope.get("user_id") if request.url.path == '/api/v1/system/auth/login': # 只有登录的才会获取登录地址 - login_location = IpLocalUtil.get_ip_location(str(request.client.host)) + login_location = IpLocalUtil.get_ip_location(request.client.host) await OperationLogService.create_log_service(data=OperationLogCreateSchema( request_path = request.url.path, diff --git a/backend/app/utils/ip_local_util.py b/backend/app/utils/ip_local_util.py index df97c8b8..0776c0b6 100644 --- a/backend/app/utils/ip_local_util.py +++ b/backend/app/utils/ip_local_util.py @@ -35,7 +35,7 @@ class IpLocalUtil: logger.error(f"IP格式不合法: {ip}") return "未知" - logger.info(f"获取IP归属地: {ip}") + logger.info(f"获取IP归属地: {ip}, 类型: {type(ip)}") # 内网IP直接返回 if ip == '127.0.0.1' or ip == 'localhost': @@ -50,6 +50,7 @@ class IpLocalUtil: if ip_result.status_code == 200: data = ip_result.json().get('data', {}) + logger.info(f"获取IP归属地成功: {data}") # "continent": "亚洲", # "country": "中国", # "zipcode": "710061",