Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/rentals.picotech.app/public_html/server/models/ drwxr-xr-x | |
| Viewing file: Select action/file-type: import { DataTypes } from 'sequelize';
import sequelize from '../config/database.js';
import bcrypt from 'bcryptjs';
const User = sequelize.define('User', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
validate: {
notEmpty: true,
len: [2, 100]
}
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true
}
},
password: {
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [6, 255]
}
},
role: {
type: DataTypes.ENUM('admin', 'manager', 'staff','renter'),
defaultValue: 'staff'
},
permissions: {
type: DataTypes.JSON,
defaultValue: ['view']
},
department: {
type: DataTypes.STRING,
allowNull: true
},
phone: {
type: DataTypes.STRING,
allowNull: true
},
avatar: {
type: DataTypes.STRING,
allowNull: true
},
is_active: {
type: DataTypes.BOOLEAN,
defaultValue: true
},
last_login: {
type: DataTypes.DATE,
allowNull: true
},
building_id: {
type: DataTypes.UUID,
allowNull: true,
},
}, {
tableName: 'users', // ✅ ensure consistent foreign key resolution
timestamps: true ,
hooks: {
beforeCreate: async (user) => {
if (user.password && !user.password.startsWith('$2a$')) {
user.password = await bcrypt.hash(user.password, 12);
}
},
beforeUpdate: async (user) => {
if (user.changed('password') && !user.password.startsWith('$2a$')) {
user.password = await bcrypt.hash(user.password, 12);
}
}
}
});
User.prototype.comparePassword = async function(candidatePassword) {
return bcrypt.compare(candidatePassword, this.password);
};
export default User; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0044 ]-- |