Files
yunrui_asset/backend/models/User.js
T
zhang1106 2826a00192 refactor(frontend): 重构状态管理使用Zustand替代Context API
feat(auth): 添加账户锁定功能及自动解锁机制
feat(user): 在用户模型中添加lockedUntil字段
feat(api): 实现账户锁定逻辑和剩余尝试次数提示

perf(3d): 优化3D场景状态管理性能
perf(floorplan): 优化平面图状态管理性能

chore(deps): 添加zustand依赖
chore(config): 更新安全配置锁定时间为3分钟

docs: 更新部分组件注释
style: 调整登录页面样式
2026-05-08 11:17:29 +08:00

82 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,
},
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;