mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added veteran pw request site, logging in prettying
This commit is contained in:
parent
03c54c7bd4
commit
b970b2eb30
4 changed files with 181 additions and 28 deletions
|
@ -45,7 +45,7 @@ const dataEditsLog = 'stats/dataEdits'
|
|||
const dailyDataCountFile = 'stats/dailyDataCount'
|
||||
const usersDbBackupPath = 'data/dbs/backup'
|
||||
|
||||
const maxVeteranPwGetCount = 5
|
||||
const maxVeteranPwGetCount = 10
|
||||
const addPWPerDay = 3 // every x day a user can give a pw
|
||||
const maxPWCount = 2 // maximum pw give opportunities a user can have at once
|
||||
const daysAfterUserGetsPWs = 2 // days after user gets pw-s
|
||||
|
@ -151,7 +151,6 @@ function GetApp () {
|
|||
app.post('/getveteranpw', function (req, res) {
|
||||
logger.LogReq(req)
|
||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||
|
||||
const tries = dbtools.Select(userDB, 'veteranPWRequests', {
|
||||
ip: ip
|
||||
})[0]
|
||||
|
@ -160,7 +159,7 @@ function GetApp () {
|
|||
if (tries.count > maxVeteranPwGetCount) {
|
||||
res.json({
|
||||
result: 'error',
|
||||
msg: 'Too many tries'
|
||||
msg: 'Too many tries from this IP'
|
||||
})
|
||||
logger.Log(`Too many veteran PW requests from ${ip}!`, logger.GetColor('cyan'))
|
||||
return
|
||||
|
@ -180,10 +179,11 @@ function GetApp () {
|
|||
}
|
||||
|
||||
const oldUserID = req.body.cid
|
||||
|
||||
if (!oldUserID) {
|
||||
res.json({
|
||||
result: 'error',
|
||||
msg: 'No CID recieved'
|
||||
msg: 'No Client ID recieved'
|
||||
})
|
||||
logger.Log(`No client ID recieved`, logger.GetColor('cyan'))
|
||||
return
|
||||
|
@ -210,14 +210,14 @@ function GetApp () {
|
|||
logger.Log(`Veteran user #${user.id} already requested password`, logger.GetColor('cyan'))
|
||||
res.json({
|
||||
result: 'error',
|
||||
msg: 'Password already requested once'
|
||||
msg: 'Password already requested'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
logger.Log(`Invalid password request with CID: ${oldUserID}`, logger.GetColor('cyan'))
|
||||
res.json({
|
||||
result: 'error',
|
||||
msg: 'no such CID'
|
||||
msg: 'No such Client ID'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -225,7 +225,6 @@ function GetApp () {
|
|||
app.post('/login', (req, res) => {
|
||||
logger.LogReq(req)
|
||||
const pw = req.body.pw
|
||||
const redirectTo = req.body.redirect
|
||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||
const user = dbtools.Select(userDB, 'users', {
|
||||
pw: pw
|
||||
|
@ -269,24 +268,17 @@ function GetApp () {
|
|||
sameSite: 'none'
|
||||
})
|
||||
|
||||
if (redirectTo) {
|
||||
res.redirect(redirectTo)
|
||||
} else {
|
||||
res.json({
|
||||
result: 'success',
|
||||
msg: 'you are now logged in'
|
||||
})
|
||||
}
|
||||
res.json({
|
||||
result: 'success',
|
||||
msg: 'you are now logged in'
|
||||
})
|
||||
logger.Log(`Successfull login with user ID: #${user.id}`, logger.GetColor('cyan'))
|
||||
} else {
|
||||
logger.Log(`Login attempt with invalid pw: ${pw}`, logger.GetColor('cyan'))
|
||||
if (redirectTo) {
|
||||
res.redirect(redirectTo) // TODO
|
||||
} else {
|
||||
res.json({
|
||||
msg: 'invalid pw'
|
||||
})
|
||||
}
|
||||
res.json({
|
||||
result: 'error',
|
||||
msg: 'Invalid password'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue