更新超级管理员

This commit is contained in:
Ubuntu
2025-12-25 10:20:49 +00:00
parent ca42261b5c
commit f1408e53a3
17 changed files with 2449 additions and 728 deletions
@@ -424,10 +424,47 @@ async def channel_login(payload: Dict[str, str], db: AsyncSession = Depends(get_
password = payload.get("password") or "temp-pass"
if not email:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="email is required")
# 查找或创建渠道用户
user = await ensure_user(email, password, db)
if user.hashed_password and not verify_password(password, user.hashed_password):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid credentials")
token = create_access_token({"sub": str(user.id), "email": email, "role": "channel_admin"})
# 如果用户没有channel_id,尝试查找或创建对应的渠道
channel_id = user.channel_id
if not channel_id:
# 查找是否有对应的渠道
from models import Channel
result = await db.execute(select(Channel).where(Channel.email == email))
channel = result.scalar_one_or_none()
if not channel:
# 创建一个默认渠道
channel = Channel(
name=f"渠道-{email.split('@')[0]}",
email=email,
password_hash=user.password_hash,
commission_rate=10.0,
channel_credit=0.0,
custom_agent_cpu=2.0,
custom_agent_memory=4.0,
status="active"
)
db.add(channel)
await db.flush()
# 更新用户的channel_id
user.channel_id = channel.id
await db.commit()
await db.refresh(user)
channel_id = channel.id
token = create_access_token({
"sub": str(user.id),
"email": email,
"role": "channel_admin",
"channelId": str(channel_id)
})
return {"token": token, "tokenType": "bearer", "email": email, "expiresIn": 60 * 60}