Files
niumalll/backend/check_admin.js

119 lines
2.7 KiB
JavaScript
Raw Permalink 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.

const { Sequelize, DataTypes } = require('sequelize');
require('dotenv').config();
// 数据库配置
const sequelize = new Sequelize(
process.env.DB_NAME || 'niumall',
process.env.DB_USERNAME || 'root',
process.env.DB_PASSWORD || 'aiotAiot123!',
{
host: process.env.DB_HOST || '129.211.213.226',
port: process.env.DB_PORT || 9527,
dialect: 'mysql',
logging: false,
dialectOptions: {
connectTimeout: 60000
}
}
);
// 定义User模型根据实际表结构
const User = sequelize.define('User', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
openid: {
type: DataTypes.STRING,
allowNull: false
},
nickname: {
type: DataTypes.STRING,
allowNull: false
},
avatar: {
type: DataTypes.STRING,
allowNull: true
},
gender: {
type: DataTypes.ENUM('male', 'female', 'other'),
allowNull: true
},
birthday: {
type: DataTypes.DATE,
allowNull: true
},
phone: {
type: DataTypes.STRING,
allowNull: true
},
email: {
type: DataTypes.STRING,
allowNull: true
},
uuid: {
type: DataTypes.STRING,
allowNull: true
},
created_at: {
type: DataTypes.DATE,
allowNull: false
},
updated_at: {
type: DataTypes.DATE,
allowNull: false
}
}, {
tableName: 'users',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at'
});
async function checkAdminUser() {
try {
console.log('Testing database connection...');
await sequelize.authenticate();
console.log('Database connection successful!');
// 查找所有用户,看看是否有管理员
console.log('Getting all users...');
const users = await User.findAll({
limit: 10,
order: [['created_at', 'DESC']]
});
console.log('Users found:', users.length);
users.forEach(user => {
console.log('- ID:', user.id, 'Nickname:', user.nickname, 'Phone:', user.phone, 'Email:', user.email);
});
// 查找可能的管理员用户(通过邮箱或昵称)
console.log('Searching for potential admin users...');
const potentialAdmins = await User.findAll({
where: {
[Sequelize.Op.or]: [
{ email: 'admin@example.com' },
{ nickname: 'admin' },
{ phone: 'admin' }
]
}
});
console.log('Potential admin users:', potentialAdmins.length);
potentialAdmins.forEach(user => {
console.log('- ID:', user.id, 'Nickname:', user.nickname, 'Phone:', user.phone, 'Email:', user.email);
});
} catch (error) {
console.error('Error:', error.message);
if (error.original) {
console.error('Original error:', error.original.message);
}
} finally {
await sequelize.close();
}
}
checkAdminUser();