41 lines
795 B
JavaScript
41 lines
795 B
JavaScript
|
|
const mongoose = require('mongoose');
|
||
|
|
|
||
|
|
const EmailVerificationCodeSchema = new mongoose.Schema({
|
||
|
|
email: {
|
||
|
|
type: String,
|
||
|
|
required: true,
|
||
|
|
lowercase: true,
|
||
|
|
trim: true,
|
||
|
|
index: true
|
||
|
|
},
|
||
|
|
code: {
|
||
|
|
type: String,
|
||
|
|
required: true
|
||
|
|
},
|
||
|
|
purpose: {
|
||
|
|
type: String,
|
||
|
|
enum: ['registration', 'password_reset'],
|
||
|
|
default: 'registration'
|
||
|
|
},
|
||
|
|
expiresAt: {
|
||
|
|
type: Date,
|
||
|
|
required: true,
|
||
|
|
index: { expireAfterSeconds: 0 } // Автоматическое удаление истекших кодов
|
||
|
|
},
|
||
|
|
verified: {
|
||
|
|
type: Boolean,
|
||
|
|
default: false
|
||
|
|
},
|
||
|
|
attempts: {
|
||
|
|
type: Number,
|
||
|
|
default: 0
|
||
|
|
},
|
||
|
|
createdAt: {
|
||
|
|
type: Date,
|
||
|
|
default: Date.now
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
module.exports = mongoose.model('EmailVerificationCode', EmailVerificationCodeSchema);
|
||
|
|
|