来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
51 lines
1.8 KiB
Bash
51 lines
1.8 KiB
Bash
#!/bin/bash
|
|
# 创建华东分公司演示管理员(BR002),用于验证订单隔离
|
|
set -euo pipefail
|
|
cd /opt/ai-fresh-delivery/server
|
|
node <<'NODE'
|
|
const { Pool } = require('pg');
|
|
const bcrypt = require('bcryptjs');
|
|
require('dotenv').config();
|
|
|
|
(async () => {
|
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
const email = 'branchadmin@meoo.local';
|
|
const username = 'branchadmin';
|
|
const password = 'BranchAdmin@123';
|
|
const branchCode = 'BR002';
|
|
|
|
const existing = await pool.query('SELECT id FROM auth.users WHERE email = $1', [email]);
|
|
let userId = existing.rows[0]?.id;
|
|
|
|
if (!userId) {
|
|
userId = 'b0000000-0000-0000-0000-000000000002';
|
|
const hash = await bcrypt.hash(password, 10);
|
|
await pool.query(
|
|
`INSERT INTO auth.users (id, email, encrypted_password, email_confirmed_at, created_at, updated_at)
|
|
VALUES ($1, $2, $3, NOW(), NOW(), NOW())
|
|
ON CONFLICT (id) DO NOTHING`,
|
|
[userId, email, hash]
|
|
);
|
|
} else {
|
|
const hash = await bcrypt.hash(password, 10);
|
|
await pool.query('UPDATE auth.users SET encrypted_password = $1 WHERE id = $2', [hash, userId]);
|
|
}
|
|
|
|
await pool.query(
|
|
`INSERT INTO profiles (id, username, full_name, branch_code, status)
|
|
VALUES ($1, $2, '华东分公司管理员', $3, 1)
|
|
ON CONFLICT (id) DO UPDATE SET username = EXCLUDED.username, full_name = EXCLUDED.full_name, branch_code = EXCLUDED.branch_code, status = EXCLUDED.status`,
|
|
[userId, username, branchCode]
|
|
);
|
|
|
|
await pool.query(`DELETE FROM user_roles WHERE user_id = $1`, [userId]);
|
|
await pool.query(`INSERT INTO user_roles (user_id, role) VALUES ($1, 'admin')`, [userId]);
|
|
|
|
console.log('Branch admin ready:', { email, username, password, branchCode, userId });
|
|
await pool.end();
|
|
})().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|
|
NODE
|