diff --git a/src/server/app.js b/src/server/app.js index ed9e840..9890639 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -60,7 +60,6 @@ require( './admin/routes.js' )( app, settings ); // admin routes require( './backend/userRoutes.js' )( app, settings ); // user routes app.use( ( request, response ) => { - console.log( 'index fallback' ); response.sendFile( path.join( __dirname + '/../webapp/dist/index.html' ) ); } ); diff --git a/src/server/backend/credentials/pwdmanager.js b/src/server/backend/credentials/pwdmanager.js index 81d27fd..ea40f9c 100644 --- a/src/server/backend/credentials/pwdmanager.js +++ b/src/server/backend/credentials/pwdmanager.js @@ -16,9 +16,9 @@ const bcrypt = require( 'bcrypt' ); const db = require( '../db/db.js' ); -module.exports.checkpassword = function checkpassword ( username, password ) { +module.exports.checkpassword = function checkpassword ( email, password ) { return new Promise( resolve => { - db.getData( 'user', username ).then( data => { + db.getDataSimple( 'user', 'email', email ).then( data => { bcrypt.compare( password, data ).then( data => { resolve( data ); } ); diff --git a/src/server/backend/db/db.js b/src/server/backend/db/db.js index bf43f5a..71937b5 100644 --- a/src/server/backend/db/db.js +++ b/src/server/backend/db/db.js @@ -10,14 +10,35 @@ const path = require( 'path' ); const fs = require( 'fs' ); -module.exports.getData = function getData ( db, searchQuery ) { +const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/settings.config.json' ) ) ); + +const dbRef = { 'user': 'libreevent_users', 'admin': 'libreevent_admin', 'order': 'libreevent_orders' }; + +let dbh; + +if ( settings.db === 'mysql' ) { + const dbsoft = require( './mysqldb.js' ); + dbh = new dbsoft(); +} else { + const dbsoft = require( './jsondb.js' ); + dbh = new dbsoft(); +} + +module.exports.getDataSimple = function getData ( db, column, searchQuery ) { return new Promise( resolve => { + dbh.query( { 'command': 'getFilteredData', 'property': column, 'searchQuery': searchQuery }, dbRef[ db ] ).then( data => { + console.log( data ); + } ).catch( error => { + console.error( error ); + } ); resolve( '$2b$05$ElMYWoMjk7567lXkIkee.e.6cxCrWU4gkfuNLB8gmGYLQQPm7gT3O' ); } ); }; -module.exports.writeData = function writeData ( db ) { - +module.exports.writeDataSimple = function writeData ( db, column, searchQuery ) { + return new Promise( ( resolve, reject ) => { + + } ); }; module.exports.getJSONData = function getData ( file ) { diff --git a/src/server/backend/db/mysqldb.js b/src/server/backend/db/mysqldb.js index 9c59161..ba8c6c9 100644 --- a/src/server/backend/db/mysqldb.js +++ b/src/server/backend/db/mysqldb.js @@ -8,14 +8,15 @@ */ const mysql = require( 'mysql' ); -const db = require( './db.js' ); +const fs = require( 'fs' ); +const path = require( 'path' ); // If the connection does not work for you, you will need to add your ip // to the whitelist of the database class SQLDB { constructor () { - this.sqlConnection = mysql.createConnection( db.getJSONDataSync( '/config/db.config.secret.json' ) ); + this.sqlConnection = mysql.createConnection( JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/db.config.secret.json' ) ) ) ); } connect () { @@ -63,7 +64,6 @@ class SQLDB { query ( operation, table ) { return new Promise( ( resolve, reject ) => { - // getAllData, getFilteredData, InnerJoin, LeftJoin, RightJoin, addData, updateData, deleteData, checkDataAvailability, fullCustomCommand (NOTE: SANITISATION WILL NOT TAKE PLACE!) /* Possible operation.command values (all need the table argument of the method call): - getAllData: no additional instructions needed @@ -102,9 +102,13 @@ class SQLDB { sanitised by the function) - operation.property (the column to search for the value), - operation.searchQuery (the value to search for [will be sanitised by method]) + - checkDataAvailability: - operation.property (the column to search for the value), - operation.searchQuery (the value to search for [will be sanitised by method]) + + - fullCustomCommand: + - operation.query (the SQL instruction to be executed) --> NOTE: This command will not be sanitised, so use only with proper sanitisation! */ let command = ''; if ( operation.command === 'getAllData' ) { diff --git a/src/server/config/settings.config.json b/src/server/config/settings.config.json index dd70dba..dc7f162 100644 --- a/src/server/config/settings.config.json +++ b/src/server/config/settings.config.json @@ -1,4 +1,5 @@ { "init": false, - "twoFA": "standard" + "twoFA": "standard", + "db": "mysql" } \ No newline at end of file diff --git a/website/dist/css/navstyle.css b/website/dist/css/navstyle.css index fc5be1c..a5680fc 100644 --- a/website/dist/css/navstyle.css +++ b/website/dist/css/navstyle.css @@ -17,7 +17,6 @@ position: fixed; display: block; z-index: 2; - width: 100%; top: 0; bottom: 0; left: 1;