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 http = require( 'http' );
const fs = require( 'fs' ); const fs = require( 'fs' );
const token = require( './backend/token.js' ); const token = require( './backend/token.js' );
const db = require( './backend/db/db.js' );
console.log( ` 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 // Set up static routes for static file serving (performance wise not
// that good, but way easier to set up) // 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' ); let file = path.join( __dirname + '/webapp/main/dist/index.html' );
console.log( '[ Server ] loading backend components' );
if ( settings.setupDone ) { if ( settings.setupDone ) {
console.log( '[ Server ] loading backend components' );
require( './backend/helperRoutes.js' )( app, settings ); // Helper routes require( './backend/helperRoutes.js' )( app, settings ); // Helper routes
require( './admin/adminRoutes.js' )( app, settings ); // admin routes require( './admin/adminRoutes.js' )( app, settings ); // admin routes
require( './admin/adminAPIRoutes.js' )( app, settings ); // admin api routes require( './admin/adminAPIRoutes.js' )( app, settings ); // admin api routes

View File

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

View File

@@ -16,7 +16,7 @@ const path = require( 'path' );
class SQLDB { class SQLDB {
constructor ( ) { 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 ( ) { connect ( ) {

View File

@@ -12,7 +12,7 @@ const html2text = require( 'html-to-text' );
const db = require( '../db/db.js' ); 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 { class MailManager {

View File

@@ -13,7 +13,7 @@ const qs = require( 'qs' );
const axios = require( 'axios' ); const axios = require( 'axios' );
const Base64 = require( 'crypto-js/enc-base64' ); const Base64 = require( 'crypto-js/enc-base64' );
const hmacSHA256 = require( 'crypto-js/hmac-sha256' ); 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/'; const baseUrl = 'https://api.payrexx.com/v1.0/';

View File

@@ -11,7 +11,7 @@ const fs = require( 'fs' );
const path = require( 'path' ); const path = require( 'path' );
const db = require( '../../../db/db.js' ); const db = require( '../../../db/db.js' );
// TODO: update config files to non-secret version for final version // 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 stripe = require( 'stripe' )( stripeConfig[ 'APIKey' ] );
const bodyParser = require( 'body-parser' ); const bodyParser = require( 'body-parser' );
const ticket = require( '../../../tickets/ticketGenerator.js' ); const ticket = require( '../../../tickets/ticketGenerator.js' );

View File

@@ -1,17 +1,17 @@
{ {
"init":true, "init":false,
"setupDone":true, "setupDone":false,
"twoFA":"enforce", "twoFA":"allow",
"twoFAMode":"enhanced", "twoFAMode":"simple",
"db":"mysql", "db":"mysql",
"payments":"stripe", "payments":"stripe",
"name":"libreevent", "name":"libreevent",
"yourDomain":"http://localhost:8080", "yourDomain":"",
"mailSender":"libreevent <no-reply@libreevent.janishutz.com>", "mailSender":"",
"maxTickets":10, "maxTickets":10,
"currency":"CHF", "currency":"USD",
"gcInterval":300, "gcInterval":300,
"ticketTimeout":900, "ticketTimeout":900,
"startPage":"modern", "startPage":"default",
"version":"1.0.0" "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 = null;
let db = require( '../backend/db/db.js' ); let pwm = null;
const pwm = require( '../admin/pwdmanager.js' );
const fs = require( 'fs' ); const fs = require( 'fs' );
const path = require( 'path' ); const path = require( 'path' );
const bodyParser = require( 'body-parser' ); const bodyParser = require( 'body-parser' );
// const db = require( '../backend/db/db.js' );
module.exports = ( app, settings ) => { module.exports = ( app, settings ) => {
let isSetupComplete = settings.setupDone;
/* /*
Setup start route that checks if setup key was correct 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 ) => { app.post( '/setup/saveBasicSettings', bodyParser.json(), ( req, res ) => {
if ( req.session.setupKeyOk ) { if ( req.session.setupKeyOk ) {
fs.writeFileSync( path.join( __dirname + '/../config/db.config.json' ), JSON.stringify( req.body.db ) ); 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 ) { if ( db === null ) {
db = require( '../backend/db/db.js' ); db = require( '../backend/db/db.js' );
pwm = require( '../admin/pwdmanager.js' );
} }
let updatedSettings = settings; let updatedSettings = settings;
updatedSettings[ 'name' ] = req.body.websiteName; updatedSettings[ 'name' ] = req.body.websiteName;
@@ -56,20 +64,29 @@ module.exports = ( app, settings ) => {
app.post( '/setup/saveRootAccount', bodyParser.json(), ( req, res ) => { app.post( '/setup/saveRootAccount', bodyParser.json(), ( req, res ) => {
if ( req.session.setupKeyOk ) { 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 => { pwm.hashPassword( req.body.password ).then( hash => {
db.writeJSONData( 'rootAccount', { 'pass': hash, 'email': req.body.mail } ); db.writeJSONData( 'rootAccount', { 'pass': hash, 'email': req.body.mail } );
let updatedSettings = settings; let updatedSettings = settings;
updatedSettings[ 'setupDone' ] = true; updatedSettings[ 'setupDone' ] = true;
updatedSettings[ 'init' ] = true;
db.saveSettings( updatedSettings ); db.saveSettings( updatedSettings );
isSetupComplete = true;
( async () => {
await db.initDB();
db.reset();
res.send( 'ok' ); res.send( 'ok' );
} )();
} ); } );
} else { } else {
res.status( 403 ).send( 'unauthorized' ); res.status( 403 ).send( 'unauthorized' );
} }
} ); } );
app.get( '/test/login', ( req, res ) => { app.get( '/getSetupStatus', ( req, res ) => {
req.session.setupKeyOk = true; res.send( isSetupComplete );
res.send( 'ok' );
} ); } );
}; };

View File

@@ -368,6 +368,7 @@ export default {
reserveTicket ( option ) { reserveTicket ( option ) {
if ( option.status == 'ok' && option.data ) { if ( option.status == 'ok' && option.data ) {
// Make call to server to reserve ticket to have server also keep track of reserved tickets // Make call to server to reserve ticket to have server also keep track of reserved tickets
let progressNot = this.$refs.notification.createNotification( 'Reserving ticket...', 20, 'progress', 'normal' );
const options = { const options = {
method: 'post', method: 'post',
body: JSON.stringify( { 'id': this.selectedSeat[ 'id' ], 'component': this.selectedSeat[ 'componentID' ], 'ticketOption': option.data, 'eventID': this.event.eventID, 'category': this.draggables[ this.selectedSeat[ 'componentID' ] ].category, 'name': this.selectedSeat.displayName } ), body: JSON.stringify( { 'id': this.selectedSeat[ 'id' ], 'component': this.selectedSeat[ 'componentID' ], 'ticketOption': option.data, 'eventID': this.event.eventID, 'category': this.draggables[ this.selectedSeat[ 'componentID' ] ].category, 'name': this.selectedSeat.displayName } ),
@@ -378,6 +379,7 @@ export default {
}; };
fetch( localStorage.getItem( 'url' ) + '/API/reserveTicket', options ).then( res => { fetch( localStorage.getItem( 'url' ) + '/API/reserveTicket', options ).then( res => {
if ( res.status === 200 ) { if ( res.status === 200 ) {
this.$refs.notification.cancelNotification( progressNot );
this.$refs[ 'component' + this.selectedSeat.componentID ][ 0 ].validateSeatSelection( this.selectedSeat, option.data ); this.$refs[ 'component' + this.selectedSeat.componentID ][ 0 ].validateSeatSelection( this.selectedSeat, option.data );
this.cartHandling( 'select', option.data ); this.cartHandling( 'select', option.data );
} else if ( res.status === 409 ) { } else if ( res.status === 409 ) {

View File

@@ -1,3 +1,4 @@
<!-- eslint-disable no-undef -->
<template> <template>
<div id="notifications" @click="handleNotifications();"> <div id="notifications" @click="handleNotifications();">
<div class="message-box" :class="[ location, size ]"> <div class="message-box" :class="[ location, size ]">
@@ -16,7 +17,7 @@
<script> <script>
export default { export default {
name: 'notificationsAPI', name: 'notifications',
props: { props: {
location: { location: {
type: String, type: String,
@@ -75,10 +76,14 @@ export default {
*/ */
try { try {
delete this.notifications[ id ]; delete this.notifications[ id ];
delete this.queue[ this.queue.findIndex( id ) ];
} catch ( error ) { } catch ( error ) {
console.log( 'notification to be deleted is nonexistent or currently being displayed' ); console.log( 'notification to be deleted is nonexistent or currently being displayed' );
} }
try {
this.queue.splice( this.queue.indexOf( id ), 1 );
} catch {
console.debug( 'queue empty' );
}
if ( this.currentlyDisplayedNotificationID == id ) { if ( this.currentlyDisplayedNotificationID == id ) {
this.handleNotifications(); this.handleNotifications();
} }
@@ -97,10 +102,13 @@ export default {
this.priority = this.notifications[ this.queue[ 0 ] ][ 'priority' ]; this.priority = this.notifications[ this.queue[ 0 ] ][ 'priority' ];
this.currentlyDisplayedNotificationID = this.notifications[ this.queue[ 0 ] ][ 'id' ]; this.currentlyDisplayedNotificationID = this.notifications[ this.queue[ 0 ] ][ 'id' ];
this.notificationDisplayTime = this.notifications[ this.queue[ 0 ] ][ 'showDuration' ]; this.notificationDisplayTime = this.notifications[ this.queue[ 0 ] ][ 'showDuration' ];
delete this.notifications[ this.queue[ 0 ] ];
this.queue.reverse(); this.queue.reverse();
this.queue.pop(); this.queue.pop();
$( '.message-box' ).css( 'z-index', 20 );
} else { } else {
this.messageType = 'hide'; this.messageType = 'hide';
$( '.message-box' ).css( 'z-index', -1 );
} }
} }
}, },
@@ -122,55 +130,15 @@ export default {
<style scoped> <style scoped>
.message-box { .message-box {
position: fixed; position: fixed;
z-index: 10; z-index: -1;
color: white; color: white;
transition: all 0.5s; transition: all 0.5s;
} width: 95vw;
right: 2.5vw;
.default { top: 1vh;
height: 10vh; height: 10vh;
width: 15vw;
} }
.small {
height: 7vh;
width: 11vw;
}
.big {
height: 12vh;
width: 17vw;
}
.bigger {
height: 15vh;
width: 20vw;
}
.huge {
height: 20vh;
width: 25vw;
}
.topleft {
top: 3vh;
left: 0.5vw;
}
.topright {
top: 3vh;
right: 0.5vw;
}
.bottomright {
bottom: 3vh;
right: 0.5vw;
}
.bottomleft {
top: 3vh;
right: 0.5vw;
}
.message-container { .message-container {
display: flex; display: flex;
@@ -218,6 +186,7 @@ export default {
} }
.progress { .progress {
z-index: 20;
background-color: rgb(0, 0, 99); background-color: rgb(0, 0, 99);
} }
@@ -233,4 +202,80 @@ export default {
transform: rotate( 720deg ); transform: rotate( 720deg );
} }
} }
@media only screen and (min-width: 750px) {
.default {
height: 10vh;
width: 32vw;
}
.small {
height: 7vh;
width: 27vw;
}
.big {
height: 12vh;
width: 38vw;
}
.bigger {
height: 15vh;
width: 43vw;
}
.huge {
height: 20vh;
width: 50vw;
}
.topleft {
top: 3vh;
left: 0.5vw;
}
.topright {
top: 3vh;
right: 0.5vw;
}
.bottomright {
bottom: 3vh;
right: 0.5vw;
}
.bottomleft {
top: 3vh;
right: 0.5vw;
}
}
@media only screen and (min-width: 1500px) {
.default {
height: 10vh;
width: 15vw;
}
.small {
height: 7vh;
width: 11vw;
}
.big {
height: 12vh;
width: 17vw;
}
.bigger {
height: 15vh;
width: 20vw;
}
.huge {
height: 20vh;
width: 25vw;
}
}
</style> </style>

View File

@@ -20,3 +20,19 @@
font-size: 400%; font-size: 400%;
} }
</style> </style>
<script>
export default {
created() {
fetch( '/getSetupStatus' ).then( res => {
if ( res.status === 200 ) {
res.text().then( text => {
if ( text !== 'true' ) {
this.$router.push( '/' );
}
} );
}
} );
}
};
</script>

View File

@@ -118,6 +118,7 @@ export default {
if ( this.formData.email.port && this.formData.email.host && this.formData.email.user && this.formData.email.pass if ( this.formData.email.port && this.formData.email.host && this.formData.email.user && this.formData.email.pass
&& this.formData.dpEmail && this.formData.display && this.formData.websiteName ) { && this.formData.dpEmail && this.formData.display && this.formData.websiteName ) {
this.formData.mailDisplay = this.formData.display + ' <' + this.formData.dpEmail + '>'; this.formData.mailDisplay = this.formData.display + ' <' + this.formData.dpEmail + '>';
let progressNot = this.$refs.notification.createNotification( 'Setting up...', 20, 'progress', 'normal' );
const options = { const options = {
method: 'post', method: 'post',
body: JSON.stringify( this.formData ), body: JSON.stringify( this.formData ),
@@ -128,7 +129,11 @@ export default {
}; };
fetch( '/setup/saveBasicSettings', options ).then( res => { fetch( '/setup/saveBasicSettings', options ).then( res => {
if ( res.status === 200 ) { if ( res.status === 200 ) {
this.$refs.notification.cancelNotification( progressNot );
this.$refs.notification.createNotification( 'Saved!', 5, 'ok', 'normal' );
setTimeout( () => {
this.continue(); this.continue();
}, 2000 );
} else { } else {
this.$refs.notification.createNotification( 'Setup key incorrect!', 5, 'error', 'normal' ); this.$refs.notification.createNotification( 'Setup key incorrect!', 5, 'error', 'normal' );
} }

View File

@@ -170,6 +170,7 @@ export default {
} }
}, },
proceed () { proceed () {
let progressNot = this.$refs.notification.createNotification( 'Saving...', 20, 'progress', 'normal' );
const options = { const options = {
method: 'post', method: 'post',
body: JSON.stringify( this.formData ), body: JSON.stringify( this.formData ),
@@ -180,9 +181,13 @@ export default {
}; };
fetch( '/setup/saveRootAccount', options ).then( res => { fetch( '/setup/saveRootAccount', options ).then( res => {
if ( res.status === 200 ) { if ( res.status === 200 ) {
this.$refs.notification.cancelNotification( progressNot );
this.$refs.notification.createNotification( 'Saved!', 5, 'ok', 'normal' );
setTimeout( () => {
sessionStorage.setItem( 'basics', JSON.stringify( this.formData ) ); sessionStorage.setItem( 'basics', JSON.stringify( this.formData ) );
this.backendStore.addVisitedSetupPages( 'complete', true ); this.backendStore.addVisitedSetupPages( 'complete', true );
this.$router.push( 'complete' ); this.$router.push( 'complete' );
}, 2000 );
} else { } else {
this.$refs.notification.createNotification( 'Setup key incorrect!', 5, 'error', 'normal' ); this.$refs.notification.createNotification( 'Setup key incorrect!', 5, 'error', 'normal' );
} }