mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Fix for logging in on site and with script
This commit is contained in:
parent
a6d260f6af
commit
fa4b29efe6
6 changed files with 26 additions and 9 deletions
|
@ -228,7 +228,8 @@ function GetApp () {
|
||||||
|
|
||||||
app.post('/login', (req, res) => {
|
app.post('/login', (req, res) => {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
const pw = req.body.pw
|
const pw = req.body.pw || false
|
||||||
|
const isScript = req.body.script
|
||||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||||
const user = dbtools.Select(userDB, 'users', {
|
const user = dbtools.Select(userDB, 'users', {
|
||||||
pw: pw
|
pw: pw
|
||||||
|
@ -239,14 +240,16 @@ function GetApp () {
|
||||||
|
|
||||||
// FIXME: Users now can only log in in one session, this might be too strict.
|
// FIXME: Users now can only log in in one session, this might be too strict.
|
||||||
const existingSessions = dbtools.Select(userDB, 'sessions', {
|
const existingSessions = dbtools.Select(userDB, 'sessions', {
|
||||||
userID: user.id
|
userID: user.id,
|
||||||
|
isScript: isScript ? 1 : 0
|
||||||
})
|
})
|
||||||
|
|
||||||
if (existingSessions.length > 0) {
|
if (existingSessions.length > 0) {
|
||||||
logger.Log(`Multiple sessions ( ${existingSessions.length} ) for #${user.id}, deleting olds`, logger.GetColor('cyan'))
|
logger.Log(`Multiple sessions ( ${existingSessions.length} ) for #${user.id}, deleting olds`, logger.GetColor('cyan'))
|
||||||
existingSessions.forEach((sess) => {
|
existingSessions.forEach((sess) => {
|
||||||
dbtools.Delete(userDB, 'sessions', {
|
dbtools.Delete(userDB, 'sessions', {
|
||||||
id: sess.id
|
id: sess.id,
|
||||||
|
isScript: isScript ? 1 : 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -263,14 +266,19 @@ function GetApp () {
|
||||||
id: sessionID,
|
id: sessionID,
|
||||||
ip: ip,
|
ip: ip,
|
||||||
userID: user.id,
|
userID: user.id,
|
||||||
|
isScript: isScript ? 1 : 0,
|
||||||
createDate: utils.GetDateString()
|
createDate: utils.GetDateString()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// https://www.npmjs.com/package/cookie
|
||||||
// TODO: cookie age
|
// TODO: cookie age
|
||||||
res.cookie('sessionID', sessionID, {
|
res.cookie('sessionID', sessionID, {
|
||||||
domain: '.frylabs.net', // TODO: use url. url: "https://api.frylabs.net"
|
domain: '.frylabs.net', // TODO: use url. url: "https://api.frylabs.net"
|
||||||
sameSite: 'none'
|
sameSite: 'none'
|
||||||
})
|
})
|
||||||
|
res.cookie('sessionID', sessionID, {
|
||||||
|
sameSite: 'none'
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
result: 'success',
|
result: 'success',
|
||||||
|
|
|
@ -81,6 +81,10 @@
|
||||||
},
|
},
|
||||||
"lastAccess": {
|
"lastAccess": {
|
||||||
"type": "text"
|
"type": "text"
|
||||||
|
},
|
||||||
|
"isScript": {
|
||||||
|
"type": "number",
|
||||||
|
"notNull": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -178,7 +178,7 @@ function GetApp () {
|
||||||
|
|
||||||
app.get('/getVeteranPw', function (req, res) {
|
app.get('/getVeteranPw', function (req, res) {
|
||||||
res.render('veteranPw', {
|
res.render('veteranPw', {
|
||||||
cid: req.query.cid
|
cid: req.query.cid || ''
|
||||||
})
|
})
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
})
|
})
|
||||||
|
|
|
@ -70,12 +70,12 @@
|
||||||
Frylabs
|
Frylabs
|
||||||
</div>
|
</div>
|
||||||
<div id='text' class='text'>
|
<div id='text' class='text'>
|
||||||
Másold be ide régi kliens ID-d, és az alapján jelszót ad. Ezt csak egyszer teheted meg, a
|
Másold be ide régi kliens ID-d, és az alapján jelszót kapsz. Ezt csak egyszer teheted meg, a
|
||||||
kapott jelszót tuti helyre írd le!
|
kapott jelszót tuti helyre írd le!
|
||||||
</div>
|
</div>
|
||||||
<div id='form'>
|
<div id='form'>
|
||||||
<div class='inputContainer'>
|
<div class='inputContainer'>
|
||||||
<input type='text' id='cid' name='pw' autocomplete="off"/>
|
<input type='text' id='cid' name='pw' value=<%= cid %> autocomplete="off"/>
|
||||||
</div>
|
</div>
|
||||||
<input type='hidden' name='redirect' value='asd' autocomplete="off"/>
|
<input type='hidden' name='redirect' value='asd' autocomplete="off"/>
|
||||||
<button id='sendButton' onclick="GetVeteranPW(this)">Submit</button>
|
<button id='sendButton' onclick="GetVeteranPW(this)">Submit</button>
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
console.clear()
|
console.clear()
|
||||||
|
|
||||||
const startHTTPS = true
|
const startHTTPS = true
|
||||||
const port = 80
|
const isRoot = process.getuid && process.getuid() === 0
|
||||||
|
const port = isRoot ? 80 : 8080
|
||||||
const httpsport = 5001
|
const httpsport = 5001
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
@ -91,6 +92,7 @@ function exit (reason) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
// https://github.com/expressjs/cors#configuration-options
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
credentials: true,
|
credentials: true,
|
||||||
origin: true
|
origin: true
|
||||||
|
@ -198,6 +200,9 @@ function LogTimerAction () {
|
||||||
logger.Log('Node version: ' + process.version)
|
logger.Log('Node version: ' + process.version)
|
||||||
logger.Log('Current working directory: ' + process.cwd())
|
logger.Log('Current working directory: ' + process.cwd())
|
||||||
logger.Log('Listening on port: ' + port)
|
logger.Log('Listening on port: ' + port)
|
||||||
|
if (isRoot) {
|
||||||
|
logger.Log('Running as root', logger.GetColor('red'))
|
||||||
|
}
|
||||||
|
|
||||||
const httpServer = http.createServer(app)
|
const httpServer = http.createServer(app)
|
||||||
httpServer.listen(port)
|
httpServer.listen(port)
|
||||||
|
|
|
@ -24,8 +24,8 @@ function CreateDB () {
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (utils.FileExists('../dbUsers/keys')) {
|
if (utils.FileExists('./ids')) {
|
||||||
const uids = utils.ReadFile('../dbUsers/keys').split('\n')
|
const uids = utils.ReadFile('./ids').split('\n')
|
||||||
|
|
||||||
uids.forEach((cid, i) => {
|
uids.forEach((cid, i) => {
|
||||||
if (!cid) { return }
|
if (!cid) { return }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue