1
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
# ============================================================
|
||||
# 创建内部员工账号
|
||||
# 用法: bash create-admin.sh 用户名 邮箱 密码
|
||||
# 示例: bash create-admin.sh zhangsan zhang@company.com 12345678
|
||||
# ============================================================
|
||||
|
||||
USERNAME=${1:-admin}
|
||||
EMAIL=${2:-admin@company.com}
|
||||
PASSWORD=${3:-Lzcc6-01}
|
||||
|
||||
echo "创建内部员工: $USERNAME ($EMAIL)"
|
||||
|
||||
docker compose exec -T backend python -c "
|
||||
from app.core.db import get_session_factory
|
||||
from app.models.user import User
|
||||
from app.models.plan import Plan
|
||||
from app.core.security import hash_password
|
||||
from sqlalchemy import select
|
||||
|
||||
factory = get_session_factory()
|
||||
with factory() as session:
|
||||
existing = session.scalars(select(User).where(User.username == '$USERNAME')).first()
|
||||
if existing:
|
||||
print(f'用户 $USERNAME 已存在,更新密码...')
|
||||
existing.password_hash = hash_password('$PASSWORD')
|
||||
existing.role = 'internal'
|
||||
session.commit()
|
||||
print('密码已更新')
|
||||
else:
|
||||
plan = session.scalars(select(Plan).where(Plan.code == 'free')).first()
|
||||
if not plan:
|
||||
plan = Plan(code='free', name='免费版', storage_quota=104857600, max_file_size=20971520, is_active=True)
|
||||
session.add(plan)
|
||||
session.flush()
|
||||
user = User(
|
||||
username='$USERNAME',
|
||||
email='$EMAIL',
|
||||
password_hash=hash_password('$PASSWORD'),
|
||||
status='active',
|
||||
role='internal',
|
||||
plan_id=plan.id,
|
||||
)
|
||||
session.add(user)
|
||||
session.commit()
|
||||
print(f'内部员工创建成功: $USERNAME / $PASSWORD')
|
||||
"
|
||||
Reference in New Issue
Block a user