mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
- Added environment variables for `RATE_LIMIT_MAX_FAILED_ATTEMPTS` and `RATE_LIMIT_LOCKOUT_TIME` - Integrated rate limiting into the login process with a maximum of 5 failed attempts - Refactored login attempt recording into the `authRouter` - Removed deprecated `recordLogin` middleware and adjusted related logic
30 lines
724 B
TypeScript
30 lines
724 B
TypeScript
import { model, Schema, Document } from 'mongoose'
|
|
|
|
export interface ILoginAttempt {
|
|
username: string
|
|
ip: string
|
|
userAgent: string
|
|
time: Date
|
|
success: boolean
|
|
message: string
|
|
}
|
|
|
|
export type LoginAttemptDocument = ILoginAttempt & Document
|
|
|
|
const LoginAttemptSchema = new Schema<LoginAttemptDocument>(
|
|
{
|
|
username: { type: String, required: true },
|
|
ip: { type: String, required: true },
|
|
userAgent: { type: String, required: true },
|
|
time: { type: Date, default: Date.now, required: true },
|
|
success: { type: Boolean, required: true },
|
|
message: { type: String },
|
|
},
|
|
{ timestamps: true }
|
|
)
|
|
|
|
export const LoginAttempt = model<LoginAttemptDocument>(
|
|
'LoginAttempt',
|
|
LoginAttemptSchema
|
|
)
|