mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Deleting old sessions fix
This commit is contained in:
parent
c8161e4dce
commit
771959ec2b
1 changed files with 17 additions and 11 deletions
|
@ -186,7 +186,6 @@ function GetApp(): ModuleType {
|
|||
temp = temp[temp.length - 1]
|
||||
|
||||
version = temp
|
||||
console.log(version)
|
||||
}
|
||||
|
||||
function LoadMOTD() {
|
||||
|
@ -680,7 +679,6 @@ function GetApp(): ModuleType {
|
|||
.replace(/"/g, '')
|
||||
.replace(/;/g, '')
|
||||
: false
|
||||
const cid = req.body.cid
|
||||
const isScript = req.body.script
|
||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||
const user: User = dbtools.Select(userDB, 'users', {
|
||||
|
@ -690,24 +688,32 @@ function GetApp(): ModuleType {
|
|||
if (user) {
|
||||
const sessionID = uuidv4()
|
||||
|
||||
const existingSessions = dbtools.Select(userDB, 'sessions', {
|
||||
userID: user.id,
|
||||
isScript: isScript ? 1 : 0,
|
||||
})
|
||||
const existingSessions = dbtools
|
||||
.Select(userDB, 'sessions', {
|
||||
userID: user.id,
|
||||
isScript: isScript ? 1 : 0,
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return new Date(a).getTime() - new Date(b).getTime()
|
||||
})
|
||||
|
||||
if (existingSessions.length >= minimumAlowwedSessions) {
|
||||
// TODO: check if sort works, and only the first few gets deleted.
|
||||
|
||||
const diff = existingSessions.length - minimumAlowwedSessions
|
||||
if (diff > 0) {
|
||||
logger.Log(
|
||||
`Multiple ${isScript ? 'script' : 'website'} sessions ( ${
|
||||
existingSessions.length
|
||||
} ) for #${user.id}, deleting olds`,
|
||||
logger.GetColor('cyan')
|
||||
)
|
||||
existingSessions.forEach((sess) => {
|
||||
for (let i = 0; i < diff; i++) {
|
||||
const id = existingSessions[i].id
|
||||
dbtools.Delete(userDB, 'sessions', {
|
||||
id: sess.id,
|
||||
id: id,
|
||||
isScript: isScript ? 1 : 0,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
dbtools.Update(
|
||||
|
@ -763,7 +769,7 @@ function GetApp(): ModuleType {
|
|||
logger.Log(
|
||||
`Login attempt with invalid pw: ${pw} to ${
|
||||
isScript ? 'script' : 'website'
|
||||
}${cid ? ', CID:' + cid : ''}`,
|
||||
}`,
|
||||
logger.GetColor('cyan')
|
||||
)
|
||||
res.json({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue