- 移除大量无实际效果的冗余配置项 - 新增维护模式拦截逻辑,支持管理员豁免 - 重构登录失败次数限制,从配置动态读取阈值 - 新增站点Logo支持与配置管理 - 优化用户管理页面数据拉取逻辑 - 新增端口批量创建范围模式功能 - 更新依赖包版本与缓存策略
83 lines
1.7 KiB
JavaScript
83 lines
1.7 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../db');
|
|
const { generateId } = require('../utils/idGenerator');
|
|
|
|
const User = sequelize.define(
|
|
'User',
|
|
{
|
|
userId: {
|
|
type: DataTypes.STRING,
|
|
primaryKey: true,
|
|
allowNull: true,
|
|
},
|
|
username: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
unique: true,
|
|
},
|
|
password: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
email: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
validate: {
|
|
isEmail: true,
|
|
},
|
|
},
|
|
phone: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
},
|
|
realName: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
},
|
|
avatar: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
},
|
|
status: {
|
|
type: DataTypes.ENUM('active', 'inactive', 'locked', 'pending'),
|
|
defaultValue: 'active',
|
|
},
|
|
lastLoginTime: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
},
|
|
lastLoginIp: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
},
|
|
loginCount: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 0,
|
|
comment: '连续登录失败次数,登录成功后重置',
|
|
},
|
|
lockedUntil: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
comment: '账户锁定过期时间,NULL表示未锁定或已解锁',
|
|
},
|
|
remark: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: true,
|
|
},
|
|
},
|
|
{
|
|
tableName: 'users',
|
|
timestamps: true,
|
|
indexes: [{ fields: ['status'] }, { fields: ['username'] }, { fields: ['email'] }],
|
|
hooks: {
|
|
beforeCreate: (user) => {
|
|
if (!user.userId) {
|
|
user.userId = generateId({ prefix: 'USR' });
|
|
}
|
|
},
|
|
},
|
|
}
|
|
);
|
|
|
|
module.exports = User;
|