mirror of
https://github.com/vernu/textbee.git
synced 2026-05-25 00:44:15 -04:00
Merge pull request #103 from vernu/limit-email-verification
limit max number of email verification requests per day
This commit is contained in:
@@ -257,6 +257,20 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async sendEmailVerificationEmail(user: UserDocument) {
|
||||
// Check if user has requested email verification more than 5 times in the last 24 hours
|
||||
const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000)
|
||||
const verificationCount = await this.emailVerificationModel.countDocuments({
|
||||
user: user._id,
|
||||
createdAt: { $gte: twentyFourHoursAgo }
|
||||
})
|
||||
|
||||
if (verificationCount >= 5) {
|
||||
throw new HttpException(
|
||||
{ error: 'Too many email verification requests. Please try again later.' },
|
||||
HttpStatus.TOO_MANY_REQUESTS
|
||||
)
|
||||
}
|
||||
|
||||
const verificationCode = uuidv4()
|
||||
const expiresAt = new Date(Date.now() + 20 * 60 * 1000) // 20 minutes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user