mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
- Added `LoginAttempt` Mongoose schema to store login history - Integrated login attempt recording into login flow (success/failure) - Created `rateLimitByAccount` middleware to block login if 10 failed attempts in 10 minutes
30 lines
721 B
TypeScript
30 lines
721 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
|
|
)
|