Initial commit: 宁夏智慧养殖监管平台

This commit is contained in:
shenquanyi
2025-08-25 15:00:46 +08:00
commit ec72c6a8b5
177 changed files with 37263 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
const bcrypt = require('bcrypt');
const { User } = require('./models');
async function createTestUser() {
try {
console.log('连接数据库...');
// 手动创建用户,直接设置加密密码
const hashedPassword = await bcrypt.hash('123456', 10);
console.log('生成的密码哈希:', hashedPassword);
// 删除现有的testuser3如果存在
await User.destroy({
where: { username: 'testuser3' }
});
// 直接插入数据库,绕过模型钩子
const user = await User.create({
username: 'testuser3',
email: 'test3@example.com',
password: hashedPassword,
status: 'active'
}, {
hooks: false // 禁用钩子
});
console.log('用户创建成功:', {
id: user.id,
username: user.username,
email: user.email
});
// 验证密码
const isValid = await bcrypt.compare('123456', user.password);
console.log('密码验证结果:', isValid);
// 使用模型方法验证
const isValidModel = await user.validPassword('123456');
console.log('模型方法验证结果:', isValidModel);
} catch (error) {
console.error('错误:', error);
} finally {
process.exit(0);
}
}
createTestUser();