fix jsondb bug -> missing promise resolution

This commit is contained in:
2023-08-25 19:11:06 +02:00
parent 59fa703595
commit 9952566b6b
5 changed files with 80 additions and 6 deletions

View File

@@ -1 +1 @@
{"libreevent_temp":{"1":{"timestamp":"Wed Aug 23 2023 15:38:21 GMT+0200 (Central European Summer Time)"},"2":{"user_id":"u9vAXhbP3iHHN5JxtRUJy4afYN1Sml1G","timestamp":"Wed Aug 23 2023 15:38:38 GMT+0200 (Central European Summer Time)","data":"{\"test4\":{\"secAr5s10\":{\"id\":\"secAr5s10\",\"component\":1,\"ticketOption\":\"2\",\"eventID\":\"test4\",\"category\":\"1\",\"name\":\"Row 6, Seat 11\"}}}"}},"libreevent_admin":{},"libreevent_orders":{},"libreevent_users":{}}
{"libreevent_temp":{},"libreevent_admin":{},"libreevent_orders":{},"libreevent_users":{"1":{"email":"info@janishutz.com","first_name":"t","name":"t","two_fa":"","user_data":"{\"country\":\"t\"}","marketing":null,"mail_confirmed":"true"}}}

View File

@@ -23,6 +23,7 @@ class JSONDB {
this.db = data[ 'db' ] ?? { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {} };
this.dbIndex = data[ 'index' ] ?? { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0 };
this.db[ 'libreevent_temp' ] = {};
this.saveToDisk();
console.log( '[ JSON-DB ] Database initialized successfully' );
return 'connection';
}
@@ -119,6 +120,7 @@ class JSONDB {
this.dbIndex[ table ] += 1;
this.db[ table ][ this.dbIndex[ table ] ] = operation.data;
this.saveToDisk();
resolve( true );
} else if ( operation.command === 'updateData' ) {
if ( !operation.property || !operation.searchQuery ) reject( 'Refusing to run destructive command: Missing Constraints' );
else {
@@ -131,6 +133,7 @@ class JSONDB {
}
}
this.saveToDisk();
resolve( true );
} else if ( operation.command === 'deleteData' ) {
if ( !operation.property || !operation.searchQuery ) reject( 'Refusing to run destructive command: Missing Constraints' );
else {
@@ -141,6 +144,7 @@ class JSONDB {
}
}
this.saveToDisk();
resolve( true );
} else if ( operation.command === 'InnerJoin' ) {
// TODO: Finish those when actually needed
} else if ( operation.command === 'LeftJoin' ) {

View File

@@ -155,7 +155,15 @@ module.exports = ( app, settings ) => {
mailManager.sendMail( request.body.mail, await twoFA.generateSignupEmail( tok, settings.yourDomain, settings.name ), 'Confirm your email', settings.mailSender );
} )();
pwdmanager.hashPassword( request.body.password ).then( hash => {
db.writeDataSimple( 'users', 'email', request.body.mail, { 'email': request.body.mail, 'pass': hash, 'first_name': request.body.firstName, 'name': request.body.name, 'two_fa': 'disabled', 'user_data': JSON.stringify( { 'country': request.body.country } ), 'marketing': request.body.newsletter ? generator.generateToken( 60 ) : null } ).then( () => {
db.writeDataSimple( 'users', 'email', request.body.mail, {
'email': request.body.mail,
'pass': hash,
'first_name': request.body.firstName,
'name': request.body.name,
'two_fa': 'disabled',
'user_data': JSON.stringify( { 'country': request.body.country } ),
'marketing': request.body.newsletter ? generator.generateToken( 60 ) : null
} ).then( () => {
request.session.loggedInUser = true;
request.session.username = request.body.mail;
response.send( 'ok' );

View File

@@ -1,5 +1,5 @@
{
"init":false,
"init":true,
"twoFA":"enforce",
"setupKey":"hello world",
"twoFAMode":"enhanced",