mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Auth middleware polish
This commit is contained in:
parent
81db237b48
commit
5f0b17a0db
5 changed files with 68 additions and 29 deletions
|
@ -62,6 +62,11 @@ function CreateDB () {
|
|||
// TODO: fill with data
|
||||
dbtools.Insert(authDB, 'users', {
|
||||
pw: 2,
|
||||
id: 2,
|
||||
notes: 'hemnlo'
|
||||
})
|
||||
dbtools.Insert(authDB, 'users', {
|
||||
pw: 1,
|
||||
id: 1,
|
||||
notes: 'hemnlo'
|
||||
})
|
||||
|
@ -84,7 +89,8 @@ app.set('views', [
|
|||
'./sharedViews'
|
||||
])
|
||||
app.use(auth({
|
||||
authDB: authDB
|
||||
authDB: authDB,
|
||||
jsonResponse: true
|
||||
}))
|
||||
app.use(express.static('public'))
|
||||
app.use(busboy({
|
||||
|
@ -128,6 +134,7 @@ app.post('/login', (req, res) => {
|
|||
logger.LogReq(req)
|
||||
const isScript = req.body.script
|
||||
const pw = req.body.pw
|
||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||
const user = dbtools.Select(authDB, 'users', {
|
||||
pw: pw
|
||||
})[0]
|
||||
|
@ -149,9 +156,17 @@ app.post('/login', (req, res) => {
|
|||
})
|
||||
}
|
||||
|
||||
dbtools.Update(authDB, 'users', {
|
||||
loginCount: user.loginCount + 1,
|
||||
lastIP: ip,
|
||||
lastLogin: new Date().toString()
|
||||
}, {
|
||||
id: user.id
|
||||
})
|
||||
|
||||
dbtools.Insert(authDB, 'sessions', {
|
||||
id: sessionID,
|
||||
ip: req.headers['cf-connecting-ip'] || req.connection.remoteAddress,
|
||||
ip: ip,
|
||||
userID: user.id,
|
||||
createDate: new Date().toString()
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue