mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 13:24:24 +00:00
reset database, update imports, prepare for build
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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!' );
|
||||
};
|
||||
|
||||
|
||||
@@ -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 ( ) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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/';
|
||||
|
||||
|
||||
@@ -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' );
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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
@@ -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}}
|
||||
{}
|
||||
@@ -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
@@ -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 );
|
||||
} );
|
||||
};
|
||||
@@ -368,6 +368,7 @@ export default {
|
||||
reserveTicket ( option ) {
|
||||
if ( option.status == 'ok' && option.data ) {
|
||||
// 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 = {
|
||||
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 } ),
|
||||
@@ -378,6 +379,7 @@ export default {
|
||||
};
|
||||
fetch( localStorage.getItem( 'url' ) + '/API/reserveTicket', options ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
this.$refs.notification.cancelNotification( progressNot );
|
||||
this.$refs[ 'component' + this.selectedSeat.componentID ][ 0 ].validateSeatSelection( this.selectedSeat, option.data );
|
||||
this.cartHandling( 'select', option.data );
|
||||
} else if ( res.status === 409 ) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<!-- eslint-disable no-undef -->
|
||||
<template>
|
||||
<div id="notifications" @click="handleNotifications();">
|
||||
<div class="message-box" :class="[ location, size ]">
|
||||
@@ -16,7 +17,7 @@
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'notificationsAPI',
|
||||
name: 'notifications',
|
||||
props: {
|
||||
location: {
|
||||
type: String,
|
||||
@@ -75,10 +76,14 @@ export default {
|
||||
*/
|
||||
try {
|
||||
delete this.notifications[ id ];
|
||||
delete this.queue[ this.queue.findIndex( id ) ];
|
||||
} catch ( error ) {
|
||||
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 ) {
|
||||
this.handleNotifications();
|
||||
}
|
||||
@@ -97,10 +102,13 @@ export default {
|
||||
this.priority = this.notifications[ this.queue[ 0 ] ][ 'priority' ];
|
||||
this.currentlyDisplayedNotificationID = this.notifications[ this.queue[ 0 ] ][ 'id' ];
|
||||
this.notificationDisplayTime = this.notifications[ this.queue[ 0 ] ][ 'showDuration' ];
|
||||
delete this.notifications[ this.queue[ 0 ] ];
|
||||
this.queue.reverse();
|
||||
this.queue.pop();
|
||||
$( '.message-box' ).css( 'z-index', 20 );
|
||||
} else {
|
||||
this.messageType = 'hide';
|
||||
$( '.message-box' ).css( 'z-index', -1 );
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -122,56 +130,16 @@ export default {
|
||||
<style scoped>
|
||||
.message-box {
|
||||
position: fixed;
|
||||
z-index: 10;
|
||||
z-index: -1;
|
||||
color: white;
|
||||
transition: all 0.5s;
|
||||
}
|
||||
|
||||
.default {
|
||||
width: 95vw;
|
||||
right: 2.5vw;
|
||||
top: 1vh;
|
||||
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 {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
@@ -182,7 +150,7 @@ export default {
|
||||
transition: all 0.5s;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
|
||||
.types {
|
||||
color: white;
|
||||
border-radius: 100%;
|
||||
@@ -191,40 +159,41 @@ export default {
|
||||
padding: 1.5%;
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
|
||||
.message {
|
||||
margin-right: 5%;
|
||||
text-align: end;
|
||||
}
|
||||
|
||||
|
||||
.ok {
|
||||
background-color: rgb(1, 71, 1);
|
||||
}
|
||||
|
||||
|
||||
.error {
|
||||
background-color: rgb(114, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
.info {
|
||||
background-color: rgb(44, 112, 151);
|
||||
}
|
||||
|
||||
|
||||
.warning {
|
||||
background-color: orange;
|
||||
}
|
||||
|
||||
|
||||
.hide {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
|
||||
.progress {
|
||||
z-index: 20;
|
||||
background-color: rgb(0, 0, 99);
|
||||
}
|
||||
|
||||
|
||||
.progress-spinner {
|
||||
animation: spin 2s infinite linear;
|
||||
}
|
||||
|
||||
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform: rotate( 0deg );
|
||||
@@ -233,4 +202,80 @@ export default {
|
||||
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>
|
||||
@@ -19,4 +19,20 @@
|
||||
h1 {
|
||||
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>
|
||||
@@ -118,6 +118,7 @@ export default {
|
||||
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.mailDisplay = this.formData.display + ' <' + this.formData.dpEmail + '>';
|
||||
let progressNot = this.$refs.notification.createNotification( 'Setting up...', 20, 'progress', 'normal' );
|
||||
const options = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( this.formData ),
|
||||
@@ -128,7 +129,11 @@ export default {
|
||||
};
|
||||
fetch( '/setup/saveBasicSettings', options ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
this.continue();
|
||||
this.$refs.notification.cancelNotification( progressNot );
|
||||
this.$refs.notification.createNotification( 'Saved!', 5, 'ok', 'normal' );
|
||||
setTimeout( () => {
|
||||
this.continue();
|
||||
}, 2000 );
|
||||
} else {
|
||||
this.$refs.notification.createNotification( 'Setup key incorrect!', 5, 'error', 'normal' );
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ export default {
|
||||
}
|
||||
},
|
||||
proceed () {
|
||||
let progressNot = this.$refs.notification.createNotification( 'Saving...', 20, 'progress', 'normal' );
|
||||
const options = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( this.formData ),
|
||||
@@ -180,9 +181,13 @@ export default {
|
||||
};
|
||||
fetch( '/setup/saveRootAccount', options ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
sessionStorage.setItem( 'basics', JSON.stringify( this.formData ) );
|
||||
this.backendStore.addVisitedSetupPages( 'complete', true );
|
||||
this.$router.push( 'complete' );
|
||||
this.$refs.notification.cancelNotification( progressNot );
|
||||
this.$refs.notification.createNotification( 'Saved!', 5, 'ok', 'normal' );
|
||||
setTimeout( () => {
|
||||
sessionStorage.setItem( 'basics', JSON.stringify( this.formData ) );
|
||||
this.backendStore.addVisitedSetupPages( 'complete', true );
|
||||
this.$router.push( 'complete' );
|
||||
}, 2000 );
|
||||
} else {
|
||||
this.$refs.notification.createNotification( 'Setup key incorrect!', 5, 'error', 'normal' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user