feat: 实现用户认证与权限管理系统
- 添加用户、角色、权限等数据模型 - 实现JWT认证中间件和密码加密 - 添加用户注册、登录、个人信息管理接口 - 实现前端认证上下文和受保护路由 - 添加登录历史记录和操作日志功能 - 提供管理员初始化脚本和修复工具 - 实现完整的登录页面和用户管理界面
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../db');
|
||||
|
||||
const LoginHistory = sequelize.define('LoginHistory', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
userId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
comment: '用户ID'
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
comment: '用户名'
|
||||
},
|
||||
realName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: '真实姓名'
|
||||
},
|
||||
loginTime: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: DataTypes.NOW,
|
||||
comment: '登录时间'
|
||||
},
|
||||
loginIp: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: '登录IP'
|
||||
},
|
||||
userAgent: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: '浏览器UA'
|
||||
},
|
||||
loginType: {
|
||||
type: DataTypes.ENUM('success', 'failed'),
|
||||
defaultValue: 'success',
|
||||
comment: '登录结果'
|
||||
},
|
||||
failReason: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: '失败原因'
|
||||
}
|
||||
}, {
|
||||
tableName: 'login_histories',
|
||||
timestamps: true,
|
||||
createdAt: 'loginTime',
|
||||
updatedAt: false
|
||||
});
|
||||
|
||||
module.exports = LoginHistory;
|
||||
Reference in New Issue
Block a user