2025-09-24 17:49:32 +08:00
|
|
|
const { User } = require('./models')
|
|
|
|
|
const bcrypt = require('bcryptjs')
|
|
|
|
|
|
|
|
|
|
async function createAdminUser() {
|
|
|
|
|
try {
|
|
|
|
|
console.log('开始创建管理员用户...')
|
|
|
|
|
|
|
|
|
|
// 检查是否已存在管理员用户
|
|
|
|
|
const existingAdmin = await User.findOne({
|
|
|
|
|
where: { username: 'admin' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (existingAdmin) {
|
|
|
|
|
console.log('管理员用户已存在,更新密码...')
|
|
|
|
|
const hashedPassword = await bcrypt.hash('admin123', 10)
|
|
|
|
|
await existingAdmin.update({
|
|
|
|
|
password: hashedPassword,
|
|
|
|
|
status: 'active'
|
|
|
|
|
})
|
|
|
|
|
console.log('✅ 管理员用户密码已更新')
|
|
|
|
|
} else {
|
|
|
|
|
console.log('创建新的管理员用户...')
|
|
|
|
|
const hashedPassword = await bcrypt.hash('admin123', 10)
|
|
|
|
|
|
|
|
|
|
await User.create({
|
|
|
|
|
username: 'admin',
|
|
|
|
|
password: hashedPassword,
|
|
|
|
|
real_name: '系统管理员',
|
|
|
|
|
email: 'admin@bank.com',
|
|
|
|
|
phone: '13800138000',
|
2025-09-25 15:53:44 +08:00
|
|
|
id_card: '110101199001010001',
|
2025-09-24 17:49:32 +08:00
|
|
|
status: 'active',
|
|
|
|
|
role_id: 1
|
|
|
|
|
})
|
|
|
|
|
console.log('✅ 管理员用户创建成功')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('管理员用户信息:')
|
|
|
|
|
console.log('用户名: admin')
|
|
|
|
|
console.log('密码: admin123')
|
|
|
|
|
console.log('状态: active')
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('创建管理员用户失败:', error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createAdminUser()
|
|
|
|
|
.then(() => {
|
|
|
|
|
console.log('管理员用户设置完成')
|
|
|
|
|
process.exit(0)
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error('脚本执行失败:', error)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
})
|