mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
PW is now the primary key, added login/logout route
This commit is contained in:
parent
9435cc6533
commit
cdcb1ccbbc
3 changed files with 40 additions and 6 deletions
|
@ -21,8 +21,10 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const busboy = require('connect-busboy')
|
const busboy = require('connect-busboy')
|
||||||
|
const cookieParser = require('cookie-parser')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
// const http = require('http')
|
// const http = require('http')
|
||||||
// const https = require('https')
|
// const https = require('https')
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ function CreateDB () {
|
||||||
}
|
}
|
||||||
CreateDB()
|
CreateDB()
|
||||||
|
|
||||||
|
app.use(cookieParser())
|
||||||
app.set('view engine', 'ejs')
|
app.set('view engine', 'ejs')
|
||||||
app.set('views', [
|
app.set('views', [
|
||||||
'./modules/api/views',
|
'./modules/api/views',
|
||||||
|
@ -108,6 +111,23 @@ function Load () {
|
||||||
|
|
||||||
Load()
|
Load()
|
||||||
|
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
|
app.get('/login', (req, res) => {
|
||||||
|
logger.LogReq(req)
|
||||||
|
// FIXME: redirect to original url
|
||||||
|
// TODO: check if pw is correct
|
||||||
|
res.cookie('pw', req.query.pw).redirect('/')
|
||||||
|
// TODO: create session
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/logout', (req, res) => {
|
||||||
|
logger.LogReq(req)
|
||||||
|
// FIXME: redirect to original url
|
||||||
|
// TODO: destroy session
|
||||||
|
res.clearCookie('pw').redirect('/')
|
||||||
|
})
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
app.get('/', function (req, res) {
|
app.get('/', function (req, res) {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"users": {
|
"users": {
|
||||||
"tableStruct": {
|
"tableStruct": {
|
||||||
"userID": {
|
"pw": {
|
||||||
"type": "number",
|
"type": "text",
|
||||||
"primary": true,
|
"primary": true,
|
||||||
"notNull": true
|
"notNull": true
|
||||||
},
|
},
|
||||||
"pw": {
|
"userID": {
|
||||||
"type": "text"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"lastIP": {
|
"lastIP": {
|
||||||
"type": "text"
|
"type": "text"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const logger = require('../../utils/logger.js')
|
const logger = require('../../utils/logger.js')
|
||||||
const dbtools = require('../../utils/dbtools.js')
|
const dbtools = require('../../utils/dbtools.js')
|
||||||
|
|
||||||
|
// TODO: session
|
||||||
|
|
||||||
module.exports = function (options) {
|
module.exports = function (options) {
|
||||||
const { debugLog, authDB } = options
|
const { debugLog, authDB } = options
|
||||||
|
|
||||||
|
@ -9,8 +11,20 @@ module.exports = function (options) {
|
||||||
logger.Log('AUTH: ' + req.url)
|
logger.Log('AUTH: ' + req.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
res.end('NO ACCESS')
|
const user = GetUserByPW(authDB, req.cookies.pw)
|
||||||
|
|
||||||
// next()
|
if (user) {
|
||||||
|
next()
|
||||||
|
} else {
|
||||||
|
res.JSON({
|
||||||
|
success: false,
|
||||||
|
msg: 'You dont have permission to acces this site'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetUserByPW (db, password) {
|
||||||
|
// TODO: find user by password
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue