mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Modules now return a function which creates app-s, qmining module auth handle
This commit is contained in:
parent
b5f9ede2cf
commit
a03f56028a
12 changed files with 1046 additions and 990 deletions
|
@ -3,7 +3,7 @@ const utils = require('../utils/utils.js')
|
|||
const dbtools = require('../utils/dbtools.js')
|
||||
|
||||
module.exports = function (options) {
|
||||
const { authDB, jsonResponse, exceptions } = options
|
||||
const { userDB, jsonResponse, exceptions } = options
|
||||
|
||||
const renderLogin = (res) => {
|
||||
if (jsonResponse) {
|
||||
|
@ -23,6 +23,12 @@ module.exports = function (options) {
|
|||
return req.url === exc
|
||||
})
|
||||
|
||||
// TODO Allowing all urls with _next in it, but not in params
|
||||
if (req.url.split('?')[0].includes('_next')) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
if (isException) {
|
||||
logger.DebugLog(`EXCEPTION: ${req.url}`, 'auth', 1)
|
||||
next()
|
||||
|
@ -35,7 +41,7 @@ module.exports = function (options) {
|
|||
return
|
||||
}
|
||||
|
||||
const user = GetUserBySessionID(authDB, sessionID, req)
|
||||
const user = GetUserBySessionID(userDB, sessionID, req)
|
||||
|
||||
if (!user) {
|
||||
logger.DebugLog(`No user:${req.url}`, 'auth', 1)
|
||||
|
@ -50,15 +56,15 @@ module.exports = function (options) {
|
|||
|
||||
logger.DebugLog(`ID #${user.id}: ${req.url}`, 'auth', 1)
|
||||
|
||||
UpdateAccess(authDB, user, ip, sessionID)
|
||||
UpdateAccess(userDB, user, ip, sessionID)
|
||||
|
||||
dbtools.Update(authDB, 'sessions', {
|
||||
dbtools.Update(userDB, 'sessions', {
|
||||
lastAccess: utils.GetDateString()
|
||||
}, {
|
||||
id: sessionID
|
||||
})
|
||||
|
||||
dbtools.Update(authDB, 'users', {
|
||||
dbtools.Update(userDB, 'users', {
|
||||
lastIP: ip,
|
||||
lastAccess: utils.GetDateString()
|
||||
}, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue