Fix/login limit (By Vincent) (#191)

This PR is originally by @Vincent23412 from #190 . Edited by @lancatlin
This commit is contained in:
Justin Lin authored and GitHub committed 2025-04-27 16:43:56 +08:00
commit 61cb36f357
7 files changed
+124 -14

No files matched your search

+1
View File
@@ -4,6 +4,7 @@ export { User, IUser } from './user.js'
export { Session, ISession } from './session.js'
export { Command, ICommand } from './command.js'
export { UserProfile, IUserProfile, IProgress } from './userProfile.js'
export { ILoginAttempt, LoginAttempt } from './loginAttempt.js'
export async function connectDB(uri: string) {
const db = await mongoose.connect(uri)
+29
View File
@@ -0,0 +1,29 @@
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
)