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)
|
logger.DebugLog(`ID #${user.id}: ${req.url}`, 'auth', 1)
|
||||||
|
|
||||||
UpdateAccess(userDB, user, sessionID)
|
|
||||||
|
|
||||||
dbtools.Update(
|
dbtools.Update(
|
||||||
userDB,
|
userDB,
|
||||||
'sessions',
|
'sessions',
|
||||||
|
@ -109,7 +107,6 @@ export default function (options: Options): any {
|
||||||
userDB,
|
userDB,
|
||||||
'users',
|
'users',
|
||||||
{
|
{
|
||||||
lastIP: '0.0.0.0',
|
|
||||||
lastAccess: utils.GetDateString(),
|
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) {
|
function GetUserBySessionID(db: any, sessionID: string) {
|
||||||
logger.DebugLog(`Getting user from db`, 'auth', 2)
|
logger.DebugLog(`Getting user from db`, 'auth', 2)
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,6 @@
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"unique": true
|
"unique": true
|
||||||
},
|
},
|
||||||
"lastIP": {
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
"notes": {
|
"notes": {
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
|
@ -46,15 +43,22 @@
|
||||||
"pwGotFromCID": {
|
"pwGotFromCID": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"defaultZero": true
|
"defaultZero": true
|
||||||
|
},
|
||||||
|
"createdBy": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sessions": {
|
"sessions": {
|
||||||
"foreignKey": [
|
"foreignKey": [
|
||||||
{
|
{
|
||||||
"keysFrom": ["userID"],
|
"keysFrom": [
|
||||||
|
"userID"
|
||||||
|
],
|
||||||
"table": "users",
|
"table": "users",
|
||||||
"keysTo": ["id"]
|
"keysTo": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tableStruct": {
|
"tableStruct": {
|
||||||
|
@ -63,10 +67,6 @@
|
||||||
"primary": true,
|
"primary": true,
|
||||||
"notNull": true
|
"notNull": true
|
||||||
},
|
},
|
||||||
"ip": {
|
|
||||||
"type": "text",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"userID": {
|
"userID": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"notNull": true
|
"notNull": true
|
||||||
|
@ -83,58 +83,5 @@
|
||||||
"notNull": true
|
"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) {
|
if (requestingUser.avaiblePWRequests <= 0) {
|
||||||
res.json({
|
res.json({
|
||||||
result: 'error',
|
result: 'error',
|
||||||
|
success: false,
|
||||||
msg:
|
msg:
|
||||||
'Too many passwords requested or cant request password yet, try later',
|
'Too many passwords requested or cant request password yet, try later',
|
||||||
})
|
})
|
||||||
|
@ -88,6 +89,7 @@ function setup(data: SubmoduleData): any {
|
||||||
pw: pw,
|
pw: pw,
|
||||||
avaiblePWRequests: 0,
|
avaiblePWRequests: 0,
|
||||||
created: utils.GetDateString(),
|
created: utils.GetDateString(),
|
||||||
|
createdBy: requestingUser.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.Log(
|
logger.Log(
|
||||||
|
@ -152,7 +154,6 @@ function setup(data: SubmoduleData): any {
|
||||||
'users',
|
'users',
|
||||||
{
|
{
|
||||||
loginCount: user.loginCount + 1,
|
loginCount: user.loginCount + 1,
|
||||||
lastIP: '0.0.0.0',
|
|
||||||
lastLogin: utils.GetDateString(),
|
lastLogin: utils.GetDateString(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -162,7 +163,6 @@ function setup(data: SubmoduleData): any {
|
||||||
|
|
||||||
dbtools.Insert(userDB, 'sessions', {
|
dbtools.Insert(userDB, 'sessions', {
|
||||||
id: sessionID,
|
id: sessionID,
|
||||||
ip: '0.0.0.0',
|
|
||||||
userID: user.id,
|
userID: user.id,
|
||||||
isScript: isScript ? 1 : 0,
|
isScript: isScript ? 1 : 0,
|
||||||
createDate: utils.GetDateString(),
|
createDate: utils.GetDateString(),
|
||||||
|
|
|
@ -54,7 +54,7 @@ function GetApp(): ModuleType {
|
||||||
auth({
|
auth({
|
||||||
userDB: userDB,
|
userDB: userDB,
|
||||||
jsonResponse: false,
|
jsonResponse: false,
|
||||||
exceptions: ['/favicon.ico', '/getVeteranPw'],
|
exceptions: ['/favicon.ico'],
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
app.use((req: Request, res, next) => {
|
app.use((req: Request, res, next) => {
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
.headers ON
|
.headers ON
|
||||||
select * from users
|
select * from users
|
||||||
select * from sessions
|
select * from sessions
|
||||||
select * from veteranPWRequests
|
|
||||||
select * from accesses
|
|
||||||
.tables
|
.tables
|
||||||
.bail
|
.bail
|
||||||
select * from EXIT
|
select * from EXIT
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue