mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Auth system
This commit is contained in:
parent
52778532dc
commit
9435cc6533
14 changed files with 637 additions and 23 deletions
|
@ -29,6 +29,8 @@ const app = express()
|
|||
const logger = require('../../utils/logger.js')
|
||||
const utils = require('../../utils/utils.js')
|
||||
const actions = require('../../utils/actions.js')
|
||||
const dbtools = require('../../utils/dbtools.js')
|
||||
const auth = require('../../modules/api/auth.middleware.js')
|
||||
|
||||
const recivedFiles = 'public/recivedfiles'
|
||||
const uloadFiles = 'public/f'
|
||||
|
@ -39,12 +41,31 @@ const versionFile = 'public/version'
|
|||
const passwordFile = 'data/dataEditorPasswords.json'
|
||||
const dataEditsLog = 'stats/dataEdits'
|
||||
const dailyDataCountFile = 'stats/dailyDataCount'
|
||||
const usersDBPath = 'data/dbs/users.db'
|
||||
const dbStructPath = './modules/api/apiDBStruct.json'
|
||||
|
||||
let authDB
|
||||
function CreateDB () {
|
||||
const dbStruct = utils.ReadJSON(dbStructPath)
|
||||
// TODO: check if path exists, create it if not
|
||||
authDB = dbtools.GetDB(usersDBPath)
|
||||
|
||||
Object.keys(dbStruct).forEach((tableName) => {
|
||||
const tableData = dbStruct[tableName]
|
||||
dbtools.CreateTable(authDB, tableName, tableData.tableStruct)
|
||||
})
|
||||
}
|
||||
CreateDB()
|
||||
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', [
|
||||
'./modules/api/views',
|
||||
'./sharedViews'
|
||||
])
|
||||
app.use(auth({
|
||||
debugLog: true,
|
||||
authDB: authDB
|
||||
}))
|
||||
app.use(express.static('public'))
|
||||
app.use(busboy({
|
||||
limits: {
|
||||
|
|
35
modules/api/apiDBStruct.json
Normal file
35
modules/api/apiDBStruct.json
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"users": {
|
||||
"tableStruct": {
|
||||
"userID": {
|
||||
"type": "number",
|
||||
"primary": true,
|
||||
"notNull": true
|
||||
},
|
||||
"pw": {
|
||||
"type": "text"
|
||||
},
|
||||
"lastIP": {
|
||||
"type": "text"
|
||||
},
|
||||
"notes": {
|
||||
"type": "text"
|
||||
},
|
||||
"loginCount": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"acesses": {
|
||||
"tableStruct": {
|
||||
"userID": {
|
||||
"type": "number",
|
||||
"primary": true,
|
||||
"notNull": true
|
||||
},
|
||||
"ip": {
|
||||
"type": "text"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
modules/api/auth.middleware.js
Normal file
16
modules/api/auth.middleware.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
const logger = require('../../utils/logger.js')
|
||||
const dbtools = require('../../utils/dbtools.js')
|
||||
|
||||
module.exports = function (options) {
|
||||
const { debugLog, authDB } = options
|
||||
|
||||
return function (req, res, next) {
|
||||
if (debugLog) {
|
||||
logger.Log('AUTH: ' + req.url)
|
||||
}
|
||||
|
||||
res.end('NO ACCESS')
|
||||
|
||||
// next()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue