Browse Source

成功启动版本

master
MSI-7950X\刘泽明 1 week ago
parent
commit
8539a5c932
  1. 8
      backend/modules/auth/router.py
  2. 2
      backend/requirements.txt
  3. 8
      docker-compose.yml
  4. 2
      frontend/Dockerfile
  5. 2
      frontend/src/views/flow/FlowEditor.vue
  6. 2
      init-db/01-init.sql

8
backend/modules/auth/router.py

@ -4,7 +4,7 @@ import jwt
from fastapi import APIRouter, Depends, HTTPException, Request from fastapi import APIRouter, Depends, HTTPException, Request
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
from passlib.context import CryptContext import bcrypt
from database import get_db from database import get_db
from models import User, UserRole, Role, RolePermission, Permission from models import User, UserRole, Role, RolePermission, Permission
@ -12,8 +12,6 @@ from schemas import LoginRequest, TokenResponse, UserOut, RoleOut
from config import settings from config import settings
router = APIRouter(prefix="/api/auth", tags=["auth"]) router = APIRouter(prefix="/api/auth", tags=["auth"])
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
async def get_permission_codes(db: AsyncSession, role_ids: list[uuid.UUID]) -> list[str]: async def get_permission_codes(db: AsyncSession, role_ids: list[uuid.UUID]) -> list[str]:
result = await db.execute( result = await db.execute(
@ -53,7 +51,7 @@ async def get_user_roles(db: AsyncSession, user_id: uuid.UUID) -> list[RoleOut]:
async def login(req: LoginRequest, db: AsyncSession = Depends(get_db)): async def login(req: LoginRequest, db: AsyncSession = Depends(get_db)):
result = await db.execute(select(User).where(User.username == req.username)) result = await db.execute(select(User).where(User.username == req.username))
user = result.scalar_one_or_none() user = result.scalar_one_or_none()
if not user or not pwd_context.verify(req.password, user.password_hash): if not user or not bcrypt.checkpw(req.password.encode('utf-8'), user.password_hash.encode('utf-8')):
raise HTTPException(401, "用户名或密码错误") raise HTTPException(401, "用户名或密码错误")
if user.status != "active": if user.status != "active":
raise HTTPException(403, "账户已被禁用") raise HTTPException(403, "账户已被禁用")
@ -97,4 +95,4 @@ async def get_me(request: Request, db: AsyncSession = Depends(get_db)):
def hash_password(password: str) -> str: def hash_password(password: str) -> str:
return pwd_context.hash(password) return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')

2
backend/requirements.txt

@ -5,7 +5,7 @@ asyncpg>=0.30.0
redis>=5.2.0 redis>=5.2.0
httpx>=0.28.0 httpx>=0.28.0
python-jose[cryptography]>=3.3.0 python-jose[cryptography]>=3.3.0
passlib[bcrypt]>=1.7.4 bcrypt>=4.0.0
pydantic>=2.0.0 pydantic>=2.0.0
pydantic-settings>=2.0.0 pydantic-settings>=2.0.0
alembic>=1.14.0 alembic>=1.14.0

8
docker-compose.yml

@ -1,5 +1,3 @@
version: "3.8"
services: services:
postgres: postgres:
image: postgres:16-alpine image: postgres:16-alpine
@ -13,7 +11,7 @@ services:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
- ./init-db:/docker-entrypoint-initdb.d - ./init-db:/docker-entrypoint-initdb.d
ports: ports:
- "5432:5432" - "5431:5432"
healthcheck: healthcheck:
test: ["CMD-SHELL", "pg_isready -U enterprise"] test: ["CMD-SHELL", "pg_isready -U enterprise"]
interval: 5s interval: 5s
@ -28,7 +26,7 @@ services:
volumes: volumes:
- redis_data:/data - redis_data:/data
ports: ports:
- "6379:6379" - "6378:6379"
backend: backend:
build: build:
@ -49,7 +47,7 @@ services:
LLM_API_BASE: ${LLM_API_BASE:-https://api.openai.com/v1} LLM_API_BASE: ${LLM_API_BASE:-https://api.openai.com/v1}
LLM_MODEL: ${LLM_MODEL:-gpt-4o-mini} LLM_MODEL: ${LLM_MODEL:-gpt-4o-mini}
ports: ports:
- "8000:8000" - "8100:8000"
volumes: volumes:
- ./backend:/app - ./backend:/app

2
frontend/Dockerfile

@ -2,7 +2,7 @@ FROM node:20-alpine AS build
WORKDIR /app WORKDIR /app
COPY package*.json ./ COPY package*.json ./
RUN npm ci RUN npm install
COPY . . COPY . .
RUN npm run build RUN npm run build

2
frontend/src/views/flow/FlowEditor.vue

@ -181,7 +181,7 @@ const visibleEdges = computed(() => {
x1: source.x + 80, y1: source.y + 100, x1: source.x + 80, y1: source.y + 100,
x2: target.x + 80, y2: target.y + 5, x2: target.x + 80, y2: target.y + 5,
} }
}).filter(Boolean) }).filter((edge): edge is { x1: number; y1: number; x2: number; y2: number } => edge !== null)
}) })
function onDragStart(e: DragEvent, node: (typeof nodeTypes)[0]) { function onDragStart(e: DragEvent, node: (typeof nodeTypes)[0]) {

2
init-db/01-init.sql

@ -196,7 +196,7 @@ INSERT INTO role_permissions (role_id, permission_id) VALUES
-- 默认用户 (密码: admin123) -- 默认用户 (密码: admin123)
INSERT INTO users (id, username, password_hash, display_name, department_id, position, status) VALUES INSERT INTO users (id, username, password_hash, display_name, department_id, position, status) VALUES
('30000000-0000-0000-0000-000000000001', 'admin', '$2b$12$LJ3m4ys3Lk0TSwHCpNqrAODgL4A.Y6FuRzOEDx4eCEoQIq.Z/EZ2y', '系统管理员', '00000000-0000-0000-0000-000000000001', '管理员', 'active'); ('30000000-0000-0000-0000-000000000001', 'admin', '$2b$12$0G/3v9vN3aJP3eGoqEse/uqyNxj6iigyGkUnZyndRN4ZURo9lDm/2', '系统管理员', '00000000-0000-0000-0000-000000000001', '管理员', 'active');
INSERT INTO user_roles (user_id, role_id) VALUES INSERT INTO user_roles (user_id, role_id) VALUES
('30000000-0000-0000-0000-000000000001', '10000000-0000-0000-0000-000000000001'); ('30000000-0000-0000-0000-000000000001', '10000000-0000-0000-0000-000000000001');

Loading…
Cancel
Save