mysql db partially integrated

This commit is contained in:
2023-07-15 17:07:15 +02:00
parent 5270317e2d
commit a8cf4ec9a4
6 changed files with 35 additions and 11 deletions

View File

@@ -60,7 +60,6 @@ require( './admin/routes.js' )( app, settings ); // admin routes
require( './backend/userRoutes.js' )( app, settings ); // user routes require( './backend/userRoutes.js' )( app, settings ); // user routes
app.use( ( request, response ) => { app.use( ( request, response ) => {
console.log( 'index fallback' );
response.sendFile( path.join( __dirname + '/../webapp/dist/index.html' ) ); response.sendFile( path.join( __dirname + '/../webapp/dist/index.html' ) );
} ); } );

View File

@@ -16,9 +16,9 @@
const bcrypt = require( 'bcrypt' ); const bcrypt = require( 'bcrypt' );
const db = require( '../db/db.js' ); const db = require( '../db/db.js' );
module.exports.checkpassword = function checkpassword ( username, password ) { module.exports.checkpassword = function checkpassword ( email, password ) {
return new Promise( resolve => { return new Promise( resolve => {
db.getData( 'user', username ).then( data => { db.getDataSimple( 'user', 'email', email ).then( data => {
bcrypt.compare( password, data ).then( data => { bcrypt.compare( password, data ).then( data => {
resolve( data ); resolve( data );
} ); } );

View File

@@ -10,14 +10,35 @@
const path = require( 'path' ); const path = require( 'path' );
const fs = require( 'fs' ); 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 => { 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' ); 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 ) { module.exports.getJSONData = function getData ( file ) {

View File

@@ -8,14 +8,15 @@
*/ */
const mysql = require( 'mysql' ); 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 // If the connection does not work for you, you will need to add your ip
// to the whitelist of the database // to the whitelist of the database
class SQLDB { class SQLDB {
constructor () { 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 () { connect () {
@@ -63,7 +64,6 @@ class SQLDB {
query ( operation, table ) { query ( operation, table ) {
return new Promise( ( resolve, reject ) => { 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): Possible operation.command values (all need the table argument of the method call):
- getAllData: no additional instructions needed - getAllData: no additional instructions needed
@@ -102,9 +102,13 @@ class SQLDB {
sanitised by the function) sanitised by the function)
- operation.property (the column to search for the value), - operation.property (the column to search for the value),
- operation.searchQuery (the value to search for [will be sanitised by method]) - operation.searchQuery (the value to search for [will be sanitised by method])
- checkDataAvailability: - checkDataAvailability:
- operation.property (the column to search for the value), - operation.property (the column to search for the value),
- operation.searchQuery (the value to search for [will be sanitised by method]) - 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 = ''; let command = '';
if ( operation.command === 'getAllData' ) { if ( operation.command === 'getAllData' ) {

View File

@@ -1,4 +1,5 @@
{ {
"init": false, "init": false,
"twoFA": "standard" "twoFA": "standard",
"db": "mysql"
} }

View File

@@ -17,7 +17,6 @@
position: fixed; position: fixed;
display: block; display: block;
z-index: 2; z-index: 2;
width: 100%;
top: 0; top: 0;
bottom: 0; bottom: 0;
left: 1; left: 1;