The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/models/server/raw/ServerEvents.ts

60 lines
1.5 KiB

import { BaseRaw, IndexSpecification } from './BaseRaw';
import { IServerEvent, IServerEventType } from '../../../../definition/IServerEvent';
export class ServerEventsRaw extends BaseRaw<IServerEvent> {
protected indexes: IndexSpecification[] = [{ key: { t: 1, ip: 1, ts: -1 } }, { key: { 't': 1, 'u.username': 1, 'ts': -1 } }];
async findLastFailedAttemptByIp(ip: string): Promise<IServerEvent | null> {
return this.findOne<IServerEvent>(
{
ip,
t: IServerEventType.FAILED_LOGIN_ATTEMPT,
},
{ sort: { ts: -1 } },
);
}
async findLastFailedAttemptByUsername(username: string): Promise<IServerEvent | null> {
return this.findOne<IServerEvent>(
{
'u.username': username,
't': IServerEventType.FAILED_LOGIN_ATTEMPT,
},
{ sort: { ts: -1 } },
);
}
async countFailedAttemptsByUsernameSince(username: string, since: Date): Promise<number> {
return this.find({
'u.username': username,
't': IServerEventType.FAILED_LOGIN_ATTEMPT,
'ts': {
$gte: since,
},
}).count();
}
countFailedAttemptsByIpSince(ip: string, since: Date): Promise<number> {
return this.find({
ip,
t: IServerEventType.FAILED_LOGIN_ATTEMPT,
ts: {
$gte: since,
},
}).count();
}
countFailedAttemptsByIp(ip: string): Promise<number> {
return this.find({
ip,
t: IServerEventType.FAILED_LOGIN_ATTEMPT,
}).count();
}
countFailedAttemptsByUsername(username: string): Promise<number> {
return this.find({
'u.username': username,
't': IServerEventType.FAILED_LOGIN_ATTEMPT,
}).count();
}
}