Files
SupplierSystem/server/src/seed-dev-passwords.ts
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

98 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Pool } from 'pg';
import { hashPassword } from './utils/password';
export const DEV_SIMPLE_PASSWORD = '123456';
/** 本地开发环境标准演示账号(用户名均为小写) */
export const DEV_KNOWN_ACCOUNTS: Array<{
username: string;
email: string;
role: string;
note: string;
}> = [
{ username: 'superadmin', email: 'superadmin@meoo.local', role: 'super_admin', note: '超级管理员' },
{ username: 'admin', email: 'admin@meoo.local', role: 'admin', note: '系统管理员' },
{ username: 'operator', email: 'operator@meoo.local', role: 'operator', note: '运营专员' },
{ username: 'finance', email: 'finance@meoo.local', role: 'finance', note: '财务专员' },
{ username: 'warehouse', email: 'warehouse@meoo.local', role: 'warehouse', note: '仓库管理员' },
{ username: 'delivery', email: 'delivery@meoo.local', role: 'delivery', note: '配送员(Web)' },
{ username: 'purchaser1', email: 'purchaser1@purchaser.meoo.local', role: 'purchaser', note: '采购员' },
{ username: 'supplier1', email: 'supplier1@supplier.meoo.local', role: 'supplier', note: '供应商(移动端)' },
{ username: 'delivery1', email: 'delivery1@delivery.meoo.local', role: 'delivery_mobile', note: '配送员(移动端)' },
];
export function assertDevPasswordResetAllowed() {
if (process.env.NODE_ENV === 'production') {
throw new Error('禁止在生产环境重置为简单密码');
}
if (process.env.ALLOW_DEV_PASSWORD_RESET !== '1' && process.env.NODE_ENV !== 'development') {
throw new Error('仅 development 环境或 ALLOW_DEV_PASSWORD_RESET=1 时可执行');
}
}
export async function resetDevPasswords(pool: Pool, password = DEV_SIMPLE_PASSWORD) {
assertDevPasswordResetAllowed();
const passwordHash = await hashPassword(password);
const users = await pool.query(`SELECT id, email FROM auth.users ORDER BY email`);
if (!users.rowCount) {
return { updated: 0, password, accounts: [] as Array<Record<string, unknown>> };
}
await pool.query(
`UPDATE auth.users SET encrypted_password = $1, updated_at = NOW() WHERE id = ANY($2::uuid[])`,
[passwordHash, users.rows.map((row) => row.id)]
);
await pool.query(
`UPDATE profiles SET
username = lower(trim(username)),
must_change_password = false
WHERE id = ANY($1::uuid[])`,
[users.rows.map((row) => row.id)]
);
const detail = await pool.query(
`SELECT
COALESCE(p.username, split_part(u.email, '@', 1)) AS username,
u.email,
COALESCE(array_remove(array_agg(DISTINCT ur.role::text), NULL), ARRAY[]::text[]) AS roles
FROM auth.users u
LEFT JOIN profiles p ON p.id = u.id
LEFT JOIN user_roles ur ON ur.user_id = u.id
GROUP BY u.id, u.email, p.username
ORDER BY u.email`
);
return {
updated: users.rowCount,
password,
accounts: detail.rows,
};
}
export function printDevAccountList(
accounts: Array<Record<string, unknown>>,
password = DEV_SIMPLE_PASSWORD
) {
console.log('');
console.log('本地开发登录账号(密码统一为 123456):');
console.log('----------------------------------------------');
for (const row of accounts) {
const username = String(row.username || '').toLowerCase();
const roles = Array.isArray(row.roles) ? row.roles.join(', ') : '';
const extra = [
row.purchaser_code ? `采购员 ${row.purchaser_code}` : '',
row.supplier_code ? `供应商 ${row.supplier_code}` : '',
row.delivery_person_code ? `配送 ${row.delivery_person_code}` : '',
]
.filter(Boolean)
.join(' · ');
console.log(`${username.padEnd(14)} ${roles.padEnd(18)} ${extra}`.trim());
}
console.log('----------------------------------------------');
console.log(`密码: ${password}`);
console.log('登录时输入「用户名」(小写),无需输入 @meoo.local');
console.log('');
}