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/note.picotech.app/public_html/src/models/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Otp = sequelize.define('Otp', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
email: {
type: DataTypes.STRING(255),
allowNull: false,
validate: {
isEmail: true,
},
},
otp_code: {
type: DataTypes.STRING(6),
allowNull: false,
},
otp_type: {
type: DataTypes.ENUM('registration', 'password_reset', 'email_change'),
allowNull: false,
defaultValue: 'registration',
},
expires_at: {
type: DataTypes.DATE,
allowNull: false,
},
is_used: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
attempts: {
type: DataTypes.INTEGER,
defaultValue: 0,
},
max_attempts: {
type: DataTypes.INTEGER,
defaultValue: 3,
},
}, {
tableName: 'otps',
timestamps: true,
indexes: [
{
unique: true,
fields: ['email', 'otp_type'],
where: {
is_used: false,
},
},
{
fields: ['expires_at'],
},
],
});
// Instance methods
Otp.prototype.isExpired = function() {
return new Date() > this.expires_at;
};
Otp.prototype.canAttempt = function() {
return this.attempts < this.max_attempts;
};
Otp.prototype.incrementAttempts = function() {
this.attempts += 1;
return this.save();
};
// Class methods
Otp.generateOTP = function(email, type = 'registration') {
const otp = Math.floor(100000 + Math.random() * 900000).toString();
const expiresAt = new Date(Date.now() + 10 * 60 * 1000); // 10 minutes
return this.create({
email,
otp_code: otp,
otp_type: type,
expires_at: expiresAt,
});
};
Otp.findValidOTP = function(email, otp, type = 'registration') {
return this.findOne({
where: {
email,
otp_code: otp,
otp_type: type,
is_used: false,
},
});
};
Otp.cleanupExpired = function() {
return this.destroy({
where: {
expires_at: {
[require('sequelize').Op.lt]: new Date(),
},
},
});
};
module.exports = Otp; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0041 ]-- |