Compare commits
4 Commits
b6b5ac61af
...
cc3a6ab0c7
| Author | SHA1 | Date | |
|---|---|---|---|
| cc3a6ab0c7 | |||
| aa3f5f6108 | |||
| 9ff89f4a7d | |||
| b04ee51020 |
10
.drone.yml
10
.drone.yml
@@ -71,7 +71,7 @@ steps:
|
||||
branch:
|
||||
- develop
|
||||
|
||||
# 部署生产环境
|
||||
# 部署生产环境(使用与测试相同的数据库配置)
|
||||
- name: deploy-prod
|
||||
image: docker:dind
|
||||
volumes:
|
||||
@@ -79,13 +79,13 @@ steps:
|
||||
path: /var/run/docker.sock
|
||||
environment:
|
||||
DATABASE_URL:
|
||||
from_secret: database_url_prod
|
||||
from_secret: database_url
|
||||
API_KEY:
|
||||
from_secret: api_key_prod
|
||||
from_secret: api_key
|
||||
JWT_SECRET:
|
||||
from_secret: jwt_secret_prod
|
||||
from_secret: jwt_secret
|
||||
CONFIG_ENCRYPT_KEY:
|
||||
from_secret: config_encrypt_key_prod
|
||||
from_secret: config_encrypt_key
|
||||
commands:
|
||||
- docker network create platform-network-prod 2>/dev/null || true
|
||||
- docker stop platform-backend-prod platform-frontend-prod || true
|
||||
|
||||
@@ -22,7 +22,7 @@ from ..models.tenant_app import TenantApp
|
||||
from ..models.tenant_wechat_app import TenantWechatApp
|
||||
|
||||
router = APIRouter(prefix="/auth", tags=["认证"])
|
||||
security = HTTPBearer()
|
||||
security = HTTPBearer(auto_error=False)
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
@@ -48,24 +48,33 @@ class ChangePasswordRequest(BaseModel):
|
||||
# 权限依赖
|
||||
|
||||
async def get_current_user(
|
||||
credentials: HTTPAuthorizationCredentials = Depends(security),
|
||||
credentials: Optional[HTTPAuthorizationCredentials] = Depends(security),
|
||||
db: Session = Depends(get_db)
|
||||
) -> User:
|
||||
"""获取当前用户"""
|
||||
if not credentials:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="需要登录认证",
|
||||
headers={"WWW-Authenticate": "Bearer"}
|
||||
)
|
||||
|
||||
token = credentials.credentials
|
||||
token_data = decode_token(token)
|
||||
|
||||
if not token_data:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Token 无效或已过期"
|
||||
detail="Token 无效或已过期",
|
||||
headers={"WWW-Authenticate": "Bearer"}
|
||||
)
|
||||
|
||||
user = db.query(User).filter(User.id == token_data.user_id).first()
|
||||
if not user or user.status != 1:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="用户不存在或已禁用"
|
||||
detail="用户不存在或已禁用",
|
||||
headers={"WWW-Authenticate": "Bearer"}
|
||||
)
|
||||
|
||||
return user
|
||||
|
||||
@@ -117,8 +117,8 @@ async def query_logs(
|
||||
"method": item.method,
|
||||
"status_code": item.status_code,
|
||||
"duration_ms": item.duration_ms,
|
||||
"ip_address": item.ip_address,
|
||||
"extra_data": item.extra_data,
|
||||
"ip_address": item.context.get("ip") if item.context else None,
|
||||
"context": item.context,
|
||||
"stack_trace": item.stack_trace,
|
||||
"log_time": str(item.log_time) if item.log_time else None
|
||||
}
|
||||
@@ -182,6 +182,7 @@ def export_csv(logs: list) -> StreamingResponse:
|
||||
|
||||
# 写入数据
|
||||
for log in logs:
|
||||
ip_address = log.context.get("ip") if log.context else ""
|
||||
writer.writerow([
|
||||
log.id,
|
||||
log.log_type,
|
||||
@@ -194,7 +195,7 @@ def export_csv(logs: list) -> StreamingResponse:
|
||||
log.method or "",
|
||||
log.status_code or "",
|
||||
log.duration_ms or "",
|
||||
log.ip_address or "",
|
||||
ip_address or "",
|
||||
str(log.log_time) if log.log_time else ""
|
||||
])
|
||||
|
||||
@@ -242,6 +243,7 @@ def export_excel(logs: list) -> StreamingResponse:
|
||||
|
||||
# 写入数据
|
||||
for row, log in enumerate(logs, 2):
|
||||
ip_address = log.context.get("ip") if log.context else ""
|
||||
ws.cell(row=row, column=1, value=log.id)
|
||||
ws.cell(row=row, column=2, value=log.log_type)
|
||||
ws.cell(row=row, column=3, value=log.level)
|
||||
@@ -253,7 +255,7 @@ def export_excel(logs: list) -> StreamingResponse:
|
||||
ws.cell(row=row, column=9, value=log.method or "")
|
||||
ws.cell(row=row, column=10, value=log.status_code or "")
|
||||
ws.cell(row=row, column=11, value=log.duration_ms or "")
|
||||
ws.cell(row=row, column=12, value=log.ip_address or "")
|
||||
ws.cell(row=row, column=12, value=ip_address or "")
|
||||
ws.cell(row=row, column=13, value=str(log.log_time) if log.log_time else "")
|
||||
|
||||
# 调整列宽
|
||||
|
||||
Reference in New Issue
Block a user