mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Db structure changes
This commit is contained in:
parent
6eef9fd1c0
commit
bf2f63e810
6 changed files with 19 additions and 93 deletions
|
@ -92,8 +92,6 @@ export default function (options: Options): any {
|
|||
|
||||
logger.DebugLog(`ID #${user.id}: ${req.url}`, 'auth', 1)
|
||||
|
||||
UpdateAccess(userDB, user, sessionID)
|
||||
|
||||
dbtools.Update(
|
||||
userDB,
|
||||
'sessions',
|
||||
|
@ -109,7 +107,6 @@ export default function (options: Options): any {
|
|||
userDB,
|
||||
'users',
|
||||
{
|
||||
lastIP: '0.0.0.0',
|
||||
lastAccess: utils.GetDateString(),
|
||||
},
|
||||
{
|
||||
|
@ -121,22 +118,6 @@ export default function (options: Options): any {
|
|||
}
|
||||
}
|
||||
|
||||
function UpdateAccess(db, user, sessionID) {
|
||||
const accesses = dbtools.Select(db, 'accesses', {
|
||||
userId: user.id,
|
||||
ip: '0.0.0.0',
|
||||
})
|
||||
|
||||
if (accesses.length === 0) {
|
||||
dbtools.Insert(db, 'accesses', {
|
||||
userID: user.id,
|
||||
ip: '0.0.0.0',
|
||||
sessionID: sessionID,
|
||||
date: utils.GetDateString(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function GetUserBySessionID(db: any, sessionID: string) {
|
||||
logger.DebugLog(`Getting user from db`, 'auth', 2)
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@ interface Options {
|
|||
excludeFromStats: Array<string>
|
||||
}
|
||||
|
||||
export default function(options: Options): any {
|
||||
export default function (options: Options): any {
|
||||
const loggableKeywords = options ? options.loggableKeywords : undefined
|
||||
const loggableModules = options ? options.loggableModules : undefined
|
||||
const exceptions = options.exceptions || []
|
||||
const excludeFromStats = options.excludeFromStats || []
|
||||
|
||||
return function(req, res, next) {
|
||||
res.on('finish', function() {
|
||||
return function (req, res, next) {
|
||||
res.on('finish', function () {
|
||||
// TODO: test this
|
||||
const isException = exceptions.some((ex) => {
|
||||
return req.url.includes(ex)
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
"type": "text",
|
||||
"unique": true
|
||||
},
|
||||
"lastIP": {
|
||||
"type": "text"
|
||||
},
|
||||
"notes": {
|
||||
"type": "text"
|
||||
},
|
||||
|
@ -46,15 +43,22 @@
|
|||
"pwGotFromCID": {
|
||||
"type": "number",
|
||||
"defaultZero": true
|
||||
},
|
||||
"createdBy": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sessions": {
|
||||
"foreignKey": [
|
||||
{
|
||||
"keysFrom": ["userID"],
|
||||
"keysFrom": [
|
||||
"userID"
|
||||
],
|
||||
"table": "users",
|
||||
"keysTo": ["id"]
|
||||
"keysTo": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
],
|
||||
"tableStruct": {
|
||||
|
@ -63,10 +67,6 @@
|
|||
"primary": true,
|
||||
"notNull": true
|
||||
},
|
||||
"ip": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
},
|
||||
"userID": {
|
||||
"type": "number",
|
||||
"notNull": true
|
||||
|
@ -83,58 +83,5 @@
|
|||
"notNull": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"accesses": {
|
||||
"foreignKey": [
|
||||
{
|
||||
"keysFrom": ["userID"],
|
||||
"table": "users",
|
||||
"keysTo": ["id"]
|
||||
}
|
||||
],
|
||||
"tableStruct": {
|
||||
"accessID": {
|
||||
"type": "integer",
|
||||
"primary": true,
|
||||
"autoIncrement": true
|
||||
},
|
||||
"userID": {
|
||||
"type": "number",
|
||||
"notNull": true
|
||||
},
|
||||
"ip": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
},
|
||||
"date": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
},
|
||||
"sessionID": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"veteranPWRequests": {
|
||||
"tableStruct": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"primary": true,
|
||||
"autoIncrement": true
|
||||
},
|
||||
"ip": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
},
|
||||
"count": {
|
||||
"type": "number",
|
||||
"defaultZero": true
|
||||
},
|
||||
"lastDate": {
|
||||
"type": "text",
|
||||
"notNull": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ function setup(data: SubmoduleData): any {
|
|||
if (requestingUser.avaiblePWRequests <= 0) {
|
||||
res.json({
|
||||
result: 'error',
|
||||
success: false,
|
||||
msg:
|
||||
'Too many passwords requested or cant request password yet, try later',
|
||||
})
|
||||
|
@ -88,6 +89,7 @@ function setup(data: SubmoduleData): any {
|
|||
pw: pw,
|
||||
avaiblePWRequests: 0,
|
||||
created: utils.GetDateString(),
|
||||
createdBy: requestingUser.id,
|
||||
})
|
||||
|
||||
logger.Log(
|
||||
|
@ -152,7 +154,6 @@ function setup(data: SubmoduleData): any {
|
|||
'users',
|
||||
{
|
||||
loginCount: user.loginCount + 1,
|
||||
lastIP: '0.0.0.0',
|
||||
lastLogin: utils.GetDateString(),
|
||||
},
|
||||
{
|
||||
|
@ -162,7 +163,6 @@ function setup(data: SubmoduleData): any {
|
|||
|
||||
dbtools.Insert(userDB, 'sessions', {
|
||||
id: sessionID,
|
||||
ip: '0.0.0.0',
|
||||
userID: user.id,
|
||||
isScript: isScript ? 1 : 0,
|
||||
createDate: utils.GetDateString(),
|
||||
|
|
|
@ -54,7 +54,7 @@ function GetApp(): ModuleType {
|
|||
auth({
|
||||
userDB: userDB,
|
||||
jsonResponse: false,
|
||||
exceptions: ['/favicon.ico', '/getVeteranPw'],
|
||||
exceptions: ['/favicon.ico'],
|
||||
})
|
||||
)
|
||||
app.use((req: Request, res, next) => {
|
||||
|
@ -90,7 +90,7 @@ function GetApp(): ModuleType {
|
|||
|
||||
routes.forEach((route) => {
|
||||
logger.DebugLog(`Added route /${route}`, 'DataEditor routes', 1)
|
||||
app.get(`/${route}`, function(req: Request, res) {
|
||||
app.get(`/${route}`, function (req: Request, res) {
|
||||
res.redirect(`${route}.html`)
|
||||
})
|
||||
})
|
||||
|
@ -99,16 +99,16 @@ function GetApp(): ModuleType {
|
|||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
app.get('/', function(req: Request, res) {
|
||||
app.get('/', function (req: Request, res) {
|
||||
res.end('hai')
|
||||
logger.LogReq(req)
|
||||
})
|
||||
|
||||
app.get('*', function(req: Request, res) {
|
||||
app.get('*', function (req: Request, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
app.post('*', function(req: Request, res) {
|
||||
app.post('*', function (req: Request, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
.headers ON
|
||||
select * from users
|
||||
select * from sessions
|
||||
select * from veteranPWRequests
|
||||
select * from accesses
|
||||
.tables
|
||||
.bail
|
||||
select * from EXIT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue