reset database, update imports, prepare for build

This commit is contained in:
2023-10-11 11:01:57 +02:00
parent e12a8cecee
commit 1633cedec2
20 changed files with 192 additions and 112 deletions

View File

@@ -15,7 +15,6 @@ const cookieParser = require( 'cookie-parser' );
const http = require( 'http' );
const fs = require( 'fs' );
const token = require( './backend/token.js' );
const db = require( './backend/db/db.js' );
console.log( `
@@ -59,14 +58,6 @@ if ( settings.setupDone ) {
} );
}
if ( !settings.init ) {
db.initDB();
db.reset();
let mutSettings = settings;
mutSettings[ 'init' ] = true;
db.saveSettings( mutSettings );
}
// Set up static routes for static file serving (performance wise not
// that good, but way easier to set up)
@@ -94,8 +85,8 @@ app.use( cookieParser() );
let file = path.join( __dirname + '/webapp/main/dist/index.html' );
console.log( '[ Server ] loading backend components' );
if ( settings.setupDone ) {
console.log( '[ Server ] loading backend components' );
require( './backend/helperRoutes.js' )( app, settings ); // Helper routes
require( './admin/adminRoutes.js' )( app, settings ); // admin routes
require( './admin/adminAPIRoutes.js' )( app, settings ); // admin api routes

View File

@@ -31,21 +31,23 @@ if ( settings.db === 'mysql' ) {
module.exports.initDB = () => {
( async() => {
console.log( '[ DB ] Setting up...' );
await dbh.setupDB();
await dbh.resetDB();
setTimeout( () => {
dbh.setupDB();
}, 2000 );
console.log( '[ DB ] Setting up complete!' );
} )();
};
module.exports.reset = () => {
console.log( '[ DB ] Resetting...' );
this.writeJSONData( 'booked', '{}' );
this.writeJSONData( 'eventDrafts', '{}' );
this.writeJSONData( 'events', '{}' );
this.writeJSONData( 'locations', '{}' );
this.writeJSONData( 'events', '{}' );
this.writeJSONData( 'rootAccount', '{}' );
this.writeJSONData( 'seatplan', '{}' );
this.writeJSONData( 'tickets', '{}' );
this.writeJSONData( 'booked', {} );
this.writeJSONData( 'eventDrafts', {} );
this.writeJSONData( 'events', {} );
this.writeJSONData( 'locations', {} );
this.writeJSONData( 'events', {} );
this.writeJSONData( 'seatplan', {} );
this.writeJSONData( 'tickets', {} );
console.log( '[ DB ] Reset complete!' );
};

View File

@@ -16,7 +16,7 @@ const path = require( 'path' );
class SQLDB {
constructor ( ) {
this.sqlConnection = mysql.createConnection( JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/db.config.secret.json' ) ) ) );
this.sqlConnection = mysql.createConnection( JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/db.config.json' ) ) ) );
}
connect ( ) {

View File

@@ -12,7 +12,7 @@ const html2text = require( 'html-to-text' );
const db = require( '../db/db.js' );
let transporter = mailer.createTransport( db.getJSONDataSync( '/config/mail.config.secret.json' ) );
let transporter = mailer.createTransport( db.getJSONDataSync( '/config/mail.config.json' ) );
class MailManager {

View File

@@ -13,7 +13,7 @@ const qs = require( 'qs' );
const axios = require( 'axios' );
const Base64 = require( 'crypto-js/enc-base64' );
const hmacSHA256 = require( 'crypto-js/hmac-sha256' );
const payrexxConfig = JSON.parse( fs.readFileSync( path.join( __dirname + '/config.payments.secret.json' ) ) );
const payrexxConfig = JSON.parse( fs.readFileSync( path.join( __dirname + '/config.payments.json' ) ) );
const baseUrl = 'https://api.payrexx.com/v1.0/';

View File

@@ -11,7 +11,7 @@ const fs = require( 'fs' );
const path = require( 'path' );
const db = require( '../../../db/db.js' );
// TODO: update config files to non-secret version for final version
const stripeConfig = JSON.parse( fs.readFileSync( path.join( __dirname + '/config.payments.secret.json' ) ) );
const stripeConfig = JSON.parse( fs.readFileSync( path.join( __dirname + '/config.payments.json' ) ) );
const stripe = require( 'stripe' )( stripeConfig[ 'APIKey' ] );
const bodyParser = require( 'body-parser' );
const ticket = require( '../../../tickets/ticketGenerator.js' );

View File

@@ -1,17 +1,17 @@
{
"init":true,
"setupDone":true,
"twoFA":"enforce",
"twoFAMode":"enhanced",
"init":false,
"setupDone":false,
"twoFA":"allow",
"twoFAMode":"simple",
"db":"mysql",
"payments":"stripe",
"name":"libreevent",
"yourDomain":"http://localhost:8080",
"mailSender":"libreevent <no-reply@libreevent.janishutz.com>",
"yourDomain":"",
"mailSender":"",
"maxTickets":10,
"currency":"CHF",
"currency":"USD",
"gcInterval":300,
"ticketTimeout":900,
"startPage":"modern",
"startPage":"default",
"version":"1.0.0"
}

View File

@@ -1 +1 @@
{"test4":{"secAr4s7":{"id":"secAr4s7","component":1,"ticketOption":"1","eventID":"test4","category":"1","name":"Row 5, Seat 8"},"secAr6s14":{"id":"secAr6s14","component":1,"ticketOption":"2","eventID":"test4","category":"1","name":"Row 7, Seat 15"},"secAr6s10":{"id":"secAr6s10","component":1,"ticketOption":"2","eventID":"test4","category":"1","name":"Row 7, Seat 11"},"comp1secAr5s11":{"id":"comp1secAr5s11","component":1,"ticketOption":"2","eventID":"test4","category":"1","name":"Row 6, Seat 12"}},"test3":{"ticket1_1":{"id":"ticket1_1","component":1,"ticketOption":"1","eventID":"test3","count":10,"category":"1","name":"Category 1 (Child)"},"ticket1":{"id":"ticket1_1","component":1,"ticketOption":"1","eventID":"test3","count":1,"category":"1","name":"Category 1 (Child)"}},"complexLocationTest":{"comp4secAr2s25":{"id":"comp4secAr2s25","component":4,"ticketOption":"2","eventID":"complexLocationTest","category":"2","name":"Row 3, Seat 26"},"comp4secAr2s26":{"id":"comp4secAr2s26","component":4,"ticketOption":"2","eventID":"complexLocationTest","category":"2","name":"Row 3, Seat 27"}}}
{}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"test2":{"locationID":"test2","name":"TestLocation2","seatplan-enabled":true,"totalSeats":352},"test":{"locationID":"test","name":"TestLocation","seatplan-enabled":false},"testLocationNoSeatplan":{"locationID":"testLocationNoSeatplan","name":"TestLocationWithoutSeatplan","seatplan-enabled":true,"totalSeats":50},"complexSeatplan":{"locationID":"complexSeatplan","name":"Complex Seat Plan","seatplan-enabled":true,"totalSeats":244}}
{}

View File

@@ -1,4 +1 @@
{
"pass": "$2b$10$56u70OdMWo/Jv5lrqaNq8OV7TxTDOPGC9tP8Ea.1zhGluHYTzuTd.",
"email": "development@janishutz.com"
}
{}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -7,15 +7,15 @@
*
*/
// let db = null;
let db = require( '../backend/db/db.js' );
const pwm = require( '../admin/pwdmanager.js' );
let db = null;
let pwm = 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 ) => {
let isSetupComplete = settings.setupDone;
/*
Setup start route that checks if setup key was correct
*/
@@ -40,9 +40,17 @@ module.exports = ( app, settings ) => {
app.post( '/setup/saveBasicSettings', bodyParser.json(), ( req, res ) => {
if ( req.session.setupKeyOk ) {
fs.writeFileSync( path.join( __dirname + '/../config/db.config.json' ), JSON.stringify( req.body.db ) );
fs.writeFileSync( path.join( __dirname + '/../config/mail.config.json' ), JSON.stringify( req.body.email ) );
let emailSettings = {};
emailSettings[ 'host' ] = req.body.email.host;
emailSettings[ 'port' ] = req.body.email.port;
emailSettings[ 'secure' ] = false;
emailSettings[ 'auth' ] = { 'user': req.body.email.user, 'pass': req.body.email.pass };
let hostSplit = req.body.email.host.split( '.' );
emailSettings[ 'tls' ] = { 'servername': ( hostSplit[ hostSplit.length - 2 ] + '.' + hostSplit[ hostSplit.length - 1 ] ) };
fs.writeFileSync( path.join( __dirname + '/../config/mail.config.json' ), JSON.stringify( emailSettings ) );
if ( db === null ) {
db = require( '../backend/db/db.js' );
pwm = require( '../admin/pwdmanager.js' );
}
let updatedSettings = settings;
updatedSettings[ 'name' ] = req.body.websiteName;
@@ -56,20 +64,29 @@ module.exports = ( app, settings ) => {
app.post( '/setup/saveRootAccount', bodyParser.json(), ( req, res ) => {
if ( req.session.setupKeyOk ) {
if ( db === null ) {
db = require( '../backend/db/db.js' );
pwm = require( '../admin/pwdmanager.js' );
}
pwm.hashPassword( req.body.password ).then( hash => {
db.writeJSONData( 'rootAccount', { 'pass': hash, 'email': req.body.mail } );
let updatedSettings = settings;
updatedSettings[ 'setupDone' ] = true;
updatedSettings[ 'init' ] = true;
db.saveSettings( updatedSettings );
res.send( 'ok' );
isSetupComplete = true;
( async () => {
await db.initDB();
db.reset();
res.send( 'ok' );
} )();
} );
} else {
res.status( 403 ).send( 'unauthorized' );
}
} );
app.get( '/test/login', ( req, res ) => {
req.session.setupKeyOk = true;
res.send( 'ok' );
app.get( '/getSetupStatus', ( req, res ) => {
res.send( isSetupComplete );
} );
};