add some setup routes already

This commit is contained in:
2023-09-06 15:27:50 +02:00
parent 667b542893
commit 4afeb7a146
12 changed files with 136 additions and 130 deletions

View File

@@ -8,19 +8,34 @@
*/
let db = null;
const fs = require( 'fs' );
const path = require( 'path' );
const bodyParser = require( 'body-parser' );
// const db = require( '../backend/db/db.js' );
module.exports = ( app, settings ) => {
/*
Admin login route that checks the password
Setup start route that checks if setup key was correct
*/
app.get( '/setup/start', ( request, response ) => {
if ( request.query.token === settings.setupToken ) {
app.post( '/setup/start', bodyParser.json(), ( request, response ) => {
if ( request.body.token === '' + fs.readFileSync( path.join( __dirname + '/../setupkey.txt' ) ) ) {
response.send( 'ok' );
} else {
response.send( 'incorrect' );
response.status( 400 ).send( 'incorrect' );
}
} );
app.get( '/setup/getKeyStatus', ( req, res ) => {
if ( req.session.setupKeyOk ) {
res.send( 'ok' );
} else {
res.status( 403 ).send( 'not authorized' );
}
} );
app.get( '/test/login', ( req, res ) => {
req.session.setupKeyOk = true;
res.send( 'ok' );
} );
};