Files
devos/prisma/set-admin-password.ts
phptits 0d6cd37579 DevOS v1 + Phase 2: unified resource model, infra ops, website deployment, AI chat ops
- Monorepo: NestJS API (Fastify) + React web (antd/ProComponents) + shared packages
- PostgreSQL/Prisma (unified resources, relations graph, audit, events, jobs)
- Auth/RBAC/workspace isolation, credential vault (AES-256-GCM)
- Servers/SSH, Docker discovery & lifecycle, Job Center
- Websites & deployments (git provider credential clone, env, health verification)
- Domains/DNS (Cloudflare adapter), certificates (TLS probe), monitoring
- Automation (cron/event/webhook HMAC + notifications), AI Gateway, MCP (29 tools)
- AI chat window (LLM function-calling + rules fallback, SSE streaming, approvals)
- Notes: Vditor WYSIWYG markdown editor, non-blocking autosave
- Tests: 35 unit/security tests; UI audit clean (desktop+mobile, deep links)
2026-09-10 06:35:55 +00:00

36 lines
1.3 KiB
TypeScript

/**
* # 管理员密码轮换脚本
* 用法:SEED_ADMIN_EMAIL=... SEED_ADMIN_PASSWORD=... bun run prisma/set-admin-password.ts
*/
import { PrismaClient } from "@prisma/client";
import { hashPassword } from "../packages/auth/src/index";
const prisma = new PrismaClient();
async function main() {
const email = process.env.SEED_ADMIN_EMAIL;
const password = process.env.SEED_ADMIN_PASSWORD;
if (!email || !password || password.length < 5) {
console.error("set SEED_ADMIN_EMAIL and SEED_ADMIN_PASSWORD (>=5 chars)");
process.exit(1);
}
if (password.length < 12) {
console.warn("[warn] weak password in use — 仅建议开发/内网环境");
}
// 按邮箱或用户名查找现有管理员
const user =
(await prisma.user.findFirst({ where: { email }, orderBy: { createdAt: "asc" } })) ??
(await prisma.user.findFirst({ where: { email: { endsWith: "@devos.local" } }, orderBy: { createdAt: "asc" } }));
if (!user) {
console.error(`admin user not found (searched email=${email} and *@devos.local)`);
process.exit(1);
}
const updated = await prisma.user.update({
where: { id: user.id },
data: { email, passwordHash: await hashPassword(password) },
});
console.log(`[fixed] account=${updated.email} (was ${user.email}) at ${new Date().toISOString()}`);
}
main().finally(() => prisma.$disconnect());