update
This commit is contained in:
112
models/UsersAuth.js
Normal file
112
models/UsersAuth.js
Normal file
@@ -0,0 +1,112 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
/**
|
||||
* UsersAuth Model - Thông tin đăng nhập người dùng
|
||||
*/
|
||||
const UsersAuth = sequelize.define('users_auth', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING(50),
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
comment: 'Tên đăng nhập duy nhất',
|
||||
},
|
||||
email: {
|
||||
type: DataTypes.STRING(100),
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isEmail: true,
|
||||
},
|
||||
comment: 'Email đăng nhập',
|
||||
},
|
||||
password_hash: {
|
||||
type: DataTypes.STRING(255),
|
||||
allowNull: false,
|
||||
comment: 'Mật khẩu đã hash',
|
||||
},
|
||||
salt: {
|
||||
type: DataTypes.STRING(255),
|
||||
allowNull: false,
|
||||
comment: 'Salt cho mật khẩu',
|
||||
},
|
||||
qr_version: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 1,
|
||||
comment: 'Phiên bản mã QR cho điểm danh',
|
||||
},
|
||||
qr_secret: {
|
||||
type: DataTypes.STRING(255),
|
||||
comment: 'Secret key cho QR code',
|
||||
},
|
||||
current_session_id: {
|
||||
type: DataTypes.STRING(255),
|
||||
comment: 'ID phiên đăng nhập hiện tại',
|
||||
},
|
||||
last_login: {
|
||||
type: DataTypes.DATE,
|
||||
comment: 'Lần đăng nhập cuối',
|
||||
},
|
||||
last_login_ip: {
|
||||
type: DataTypes.STRING(50),
|
||||
comment: 'IP đăng nhập cuối',
|
||||
},
|
||||
login_count: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
comment: 'Số lần đăng nhập',
|
||||
},
|
||||
login_attempts: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
comment: 'Số lần thử đăng nhập',
|
||||
},
|
||||
is_active: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true,
|
||||
comment: 'Trạng thái tài khoản',
|
||||
},
|
||||
is_locked: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
comment: 'Tài khoản bị khóa',
|
||||
},
|
||||
failed_login_attempts: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
comment: 'Số lần đăng nhập thất bại',
|
||||
},
|
||||
locked_until: {
|
||||
type: DataTypes.DATE,
|
||||
comment: 'Khóa tài khoản đến',
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
},
|
||||
}, {
|
||||
tableName: 'users_auth',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{ fields: ['username'], unique: true },
|
||||
{ fields: ['email'], unique: true },
|
||||
{ fields: ['is_active'] },
|
||||
{ fields: ['qr_version'] },
|
||||
{ fields: ['current_session_id'] },
|
||||
],
|
||||
comment: 'Bảng quản lý thông tin đăng nhập người dùng',
|
||||
});
|
||||
|
||||
module.exports = UsersAuth;
|
||||
Reference in New Issue
Block a user